From 9e662fe379a64983298d1dd6f8f1e5c7fa22496f Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Mon, 4 Mar 2024 15:48:35 +0100 Subject: [PATCH] Ensure compatibility with a single shared libvips library See: #372. --- lib/vips.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/vips.rb b/lib/vips.rb index f0e7461..8994909 100644 --- a/lib/vips.rb +++ b/lib/vips.rb @@ -42,7 +42,19 @@ class << self extend FFI::Library - ffi_lib library_name("glib-2.0", 0) + if FFI::Platform.windows? + # On Windows, `GetProcAddress()` can only search in a specified DLL and + # doesn't look into its dependent libraries for symbols. Therefore, we + # check if the GLib DLLs are available. If these can not be found, we + # assume that GLib is statically linked into libvips. + ffi_lib ['libglib-2.0-0.dll', 'libvips-42.dll'] + else + # macOS and *nix uses `dlsym()`, which also searches for named symbols + # in the dependencies of the shared library. Therefore, we can support + # a single shared libvips library with all dependencies statically + # linked. + ffi_lib library_name("vips", 42) + end attach_function :g_malloc, [:size_t], :pointer @@ -134,7 +146,11 @@ def self.set_log_domain domain module GObject extend FFI::Library - ffi_lib library_name("gobject-2.0", 0) + if FFI::Platform.windows? + ffi_lib ['libgobject-2.0-0.dll', 'libvips-42.dll'] + else + ffi_lib library_name("vips", 42) + end # we can't just use ulong, windows has different int sizing rules if FFI::Platform::ADDRESS_SIZE == 64