|
54 | 54 |
|
55 | 55 | # yuk
|
56 | 56 | if _is_windows:
|
57 |
| - _glib_libname = 'libglib-2.0-0.dll' |
58 |
| - _gobject_libname = 'libgobject-2.0-0.dll' |
59 |
| - _vips_libname = 'libvips-42.dll' |
| 57 | + vips_lib = ffi.dlopen('libvips-42.dll') |
60 | 58 | elif _is_mac:
|
61 |
| - _glib_libname = None |
62 |
| - _vips_libname = 'libvips.42.dylib' |
63 |
| - _gobject_libname = 'libgobject-2.0.dylib' |
| 59 | + vips_lib = ffi.dlopen('libvips.42.dylib') |
64 | 60 | else:
|
65 |
| - _glib_libname = None |
66 |
| - _vips_libname = 'libvips.so.42' |
67 |
| - _gobject_libname = 'libgobject-2.0.so.0' |
68 |
| - |
69 |
| - # possibly use ctypes.util.find_library() to locate the lib? |
70 |
| - gobject_lib = ffi.dlopen(_gobject_libname) |
71 |
| - vips_lib = ffi.dlopen(_vips_libname) |
72 |
| - if _glib_libname: |
73 |
| - glib_lib = ffi.dlopen(_glib_libname) |
74 |
| - else: |
75 |
| - glib_lib = gobject_lib |
| 61 | + vips_lib = ffi.dlopen('libvips.so.42') |
76 | 62 |
|
77 | 63 | logger.debug('Loaded lib %s', vips_lib)
|
78 |
| - logger.debug('Loaded lib %s', gobject_lib) |
| 64 | + |
| 65 | + if _is_windows: |
| 66 | + # On Windows, `GetProcAddress()` can only search in a specified DLL and |
| 67 | + # doesn't look into its dependent libraries for symbols. Therefore, we |
| 68 | + # check if the GLib DLLs are available. If these can not be found, we |
| 69 | + # assume that GLib is statically linked into libvips. |
| 70 | + try: |
| 71 | + glib_lib = ffi.dlopen('libglib-2.0-0.dll') |
| 72 | + gobject_lib = ffi.dlopen('libgobject-2.0-0.dll') |
| 73 | + |
| 74 | + logger.debug('Loaded lib %s', glib_lib) |
| 75 | + logger.debug('Loaded lib %s', gobject_lib) |
| 76 | + except Exception: |
| 77 | + glib_lib = vips_lib |
| 78 | + gobject_lib = vips_lib |
| 79 | + else: |
| 80 | + # macOS and *nix uses `dlsym()`, which also searches for named symbols |
| 81 | + # in the dependencies of the shared library. Therefore, we can support |
| 82 | + # a single shared libvips library with all dependencies statically |
| 83 | + # linked. |
| 84 | + glib_lib = vips_lib |
| 85 | + gobject_lib = vips_lib |
79 | 86 |
|
80 | 87 | ffi.cdef('''
|
81 | 88 | int vips_init (const char* argv0);
|
|
0 commit comments