[PATCH] Poppler-0.18.typelib on macOS (Homebrew) can't work because of incorrect dylib path
Submitted by Wataru Shimizu
Assigned to poppler-bugs
Link to original bug (#106417)
Description
Created attachment 139385 Patch that adds --library-path of g-ir-scanner to fix wrong path setting of typelib on macOS
Poppler-0.18.typelib install by homebrew can't work correctly because of the wrong library path setting. Here is the sample code and the error message:
---- poppler-test.rb ---- #!/usr/bin/env ruby
require 'poppler'
$ ./poppler-test.rb (null)-WARNING **: Failed to load shared library '@rpath/libpoppler-glib.8.dylib' referenced by the typelib: dlopen(@rpath/libpoppler-glib.8.dylib, 9): image not found
It tries to load the path (@rpath/libppoppler-glib.8.dylib), but dlopen can't handle "@rpath". It should be an abosulte path (e.g. /usr/local/Cellar/poppler/0.64.0/libpoppler-glib.8.dylib).
I investigated the reason. When g-ir-scanner generates Poppler-0.18.gir from libpoppler-glib.8.dylib, it embeds the "install name" of the dylib into it. Then g-ir-compiler compiles Poppler-0.18.typelib from Poppler-0.18.gir. It means that if the install name of the dylib is @rpath style, typelib refers dylib with @rpath style path, so the typelib cannot be used. AFAIK, to generate gir and typelib correctly, the install name of dylib must be an absolute path, but the current poppler.rb (build setting of homebrew) generates dylib with @rpath style install name. poppler.rb: https://github.com/Homebrew/homebrew-core/blob/master/Formula/poppler.rb
More precisely, it generates and installs libpoppler-glib.8.dylib with @rpath style (line 80-81), then modifies the installed binary to absolute path style (line 92-98). But the binary in the building process must be absolute path style.
It can be changed by cmake option "-DCMAKE_INSTALL_NAME_DIR=/path/to/lib -DCMKAE_BUILD_WITH_INSTALL_RPATH=ON" (I will propose homebrew-core to use these options instead of line 92-98). However, this modification causes another problem. If the dylib has abosulte path style install name and --no-libtool option is set to g-ir-scanner, it fails to generate gir. To fix this problem, it needs to specify --library-path option to refer the directory where libpoppler-glib.8.dylib exists. (See https://gitlab.gnome.org/GNOME/gobject-introspection/merge_requests/11 for more detail).
During the building process, libpoppler-glib.8.dylib is placed at ${CMAKE_CURRENT_BINARY_DIR}, so I propose to set it. See the attachment patch file for the detail.
Attachment 139385, "Patch that adds --library-path of g-ir-scanner to fix wrong path setting of typelib on macOS":
patch1.txt