Bug 106417

Summary: [PATCH] Poppler-0.18.typelib on macOS (Homebrew) can't work because of incorrect dylib path
Product: poppler Reporter: Wataru Shimizu <waruzilla>
Component: glib frontendAssignee: poppler-bugs <poppler-bugs>
Status: RESOLVED MOVED QA Contact:
Severity: major    
Priority: medium CC: yan12125
Version: unspecified   
Hardware: x86-64 (AMD64)   
OS: Mac OS X (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: Patch that adds --library-path of g-ir-scanner to fix wrong path setting of typelib on macOS

Description Wataru Shimizu 2018-05-06 02:25:40 UTC
Created attachment 139385 [details]
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.
Comment 1 GitLab Migration User 2018-08-20 21:34:19 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/poppler/poppler/issues/18.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.