<html>
    <head>
      <base href="https://bugs.freedesktop.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Poppler-0.18.typelib on macOS (Homebrew) can't work because of incorrect dylib path"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=106417">106417</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Poppler-0.18.typelib on macOS (Homebrew) can't work because of incorrect dylib path
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>poppler
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>x86-64 (AMD64)
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Mac OS X (All)
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>major
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>glib frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>poppler-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>waruzilla@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=139385" name="attach_139385" title="Patch that adds --library-path of g-ir-scanner to fix wrong path setting of typelib on macOS">attachment 139385</a> <a href="attachment.cgi?id=139385&action=edit" title="Patch that adds --library-path of g-ir-scanner to fix wrong path setting of typelib on macOS">[details]</a></span>
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:
<a href="https://github.com/Homebrew/homebrew-core/blob/master/Formula/poppler.rb">https://github.com/Homebrew/homebrew-core/blob/master/Formula/poppler.rb</a>

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
<a href="https://gitlab.gnome.org/GNOME/gobject-introspection/merge_requests/11">https://gitlab.gnome.org/GNOME/gobject-introspection/merge_requests/11</a> 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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>