Re: [gtk-osx-users] Need to explicitly export DYLD_FALLBACK_LIBRARY_PATH



On 29/09/19, at 23:40, John Ralls wrote:

On Sep 29, 2019, at 2:32 PM, John Ralls <jralls ceridwen us> wrote:



On Sep 29, 2019, at 12:25 PM, Timo <timomlists gmail com> wrote:

On 29/09/19, at 00:26, John Ralls wrote:
On Sep 28, 2019, at 10:00 AM, Timo <timomlists gmail com> wrote:

On 28/09/19, at 18:45, John Ralls wrote:
On Sep 28, 2019, at 9:30 AM, Timo <timomlists gmail com> wrote:

On 28/09/19, at 16:17, John Ralls wrote:
On Sep 28, 2019, at 3:20 AM, Timo via gtk-osx-users-list <gtk-osx-users-list gnome org> wrote:

Hello, I followed the build instructions on the wiki and everything's built correctly. However my application 
fails to run with a warning about libpango-1.0.0.dylib not being found and then a traceback. I can narrow it 
down to just doing a `from gi.repository import Gtk`.

    bash-3.2$ python3
    Python 3.6.8 (default, Sep 24 2019, 17:23:22)
    [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
from gi.repository import Gtk
    ** (process:45468): WARNING **: 20:30:34.767: Failed to load shared library 'libpango-1.0.0.dylib' 
referenced by the typelib: dlopen(libpango-1.0.0.dylib, 9): image not found
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<frozen importlib._bootstrap>", line 971, in _find_and_load
      File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
      File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
      File "/Users/gtk3/gtk/inst/lib/python3.6/site-packages/gi/importer.py", line 145, in load_module
        importlib.import_module('gi.repository.' + dep.split("-")[0])
      File "/Users/gtk3/gtk/inst/lib/python3.6/importlib/__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 994, in _gcd_import
      File "<frozen importlib._bootstrap>", line 971, in _find_and_load
      File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
      File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
      File "/Users/gtk3/gtk/inst/lib/python3.6/site-packages/gi/importer.py", line 145, in load_module
        importlib.import_module('gi.repository.' + dep.split("-")[0])
      File "/Users/gtk3/gtk/inst/lib/python3.6/importlib/__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 994, in _gcd_import
      File "<frozen importlib._bootstrap>", line 971, in _find_and_load
      File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
      File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
      File "/Users/gtk3/gtk/inst/lib/python3.6/site-packages/gi/importer.py", line 146, in load_module
        dynamic_module = load_overrides(introspection_module)
      File "/Users/gtk3/gtk/inst/lib/python3.6/site-packages/gi/overrides/__init__.py", line 118, in 
load_overrides
        override_mod = importlib.import_module(override_package_name)
      File "/Users/gtk3/gtk/inst/lib/python3.6/importlib/__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "/Users/gtk3/gtk/inst/lib/python3.6/site-packages/gi/overrides/Pango.py", line 41, in <module>
        FontDescription = override(FontDescription)
      File "/Users/gtk3/gtk/inst/lib/python3.6/site-packages/gi/overrides/__init__.py", line 195, in override
        assert g_type != TYPE_NONE
    AssertionError


Explicitly setting DYLD_FALLBACK_LIBRARY_PATH seems to fix the problem:

    bash-3.2$ export DYLD_FALLBACK_LIBRARY_PATH=/Users/gtk3/gtk/inst/lib
    bash-3.2$ python3
    Python 3.6.8 (default, Sep 24 2019, 17:23:22)
    [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
from gi.repository import Gtk
    (.:45493): Gtk-WARNING **: 20:33:47.938: Locale not supported by C library.
        Using the fallback 'C' locale.
    __main__:1: PyGIWarning: Gtk was imported without specifying a version first. Use 
gi.require_version('Gtk', '3.0') before import to ensure that the right version gets loaded.


However the same problem happens when I bundle the application. Again, only doing the GTK import in the 
myapp_launcher.py file gives the same error (launcher file taken from gtk-mac-bundler example and Gramps for 
the updated version).

It already has `environ['DYLD_LIBRARY_PATH'] = bundle_lib`, but even adding 
`environ['DYLD_FALLBACK_LIBRARY_PATH'] = bundle_lib` makes no differences. Printing `bundle_lib` points to 
the lib dir inside the bundle and printing `os.path.exists(bundle_lib, 'libpango-1.0.0.dylib')` shows the 
file is actually there. So it's not picking up the Python set env variable.

It's only after I do `export DYLD_FALLBACK_LIBRARY_PATH=/path/to/myapp_bundle.app/Contents/Resources/lib` 
that the bundled app will run, but is of course only feasible to do on my dev machine.

Is it my environment that's tainted somehow? Did the build not correctly pick up paths?
It mostly has to do with meson and rpaths. The latest commit to gtk-mac-bundler, 
https://gitlab.gnome.org/GNOME/gtk-mac-bundler/commit/93edee7e2d0ec8230aaf5acb21452202b10cd678, was supposed 
to fix it, but meson's behavior has been something of a moving target.
I used the git clone method for installing gtk-mac-bundler, not the 0.7.4 package in case that matters.

What are the installed names (use otool -L and look at the first line) of libpango-1.0.0.dylib in your 
installed prefix and in your bundle?
gtk/inst/lib/libpango-1.0.0.dylib:
    /Users/gtk3/gtk/inst/lib/libpango-1.0.0.dylib (compatibility version 4401.0.0, current version 4401.6.0)

myapp.app/Contents/Resources/lib/libpango-1.0.0.dylib:
    @executable_path/../Resources//lib/libpango-1.0.0.dylib (compatibility version 4401.0.0, current version 
4401.6.0)

Looks like there's a double slash between Resources and lib. There are some more lines starting with 
@executable_path for other libs in this output, but slashes look correct:

    @executable_path/../Resources/lib/libglib-2.0.0.dylib (compatibility version 6001.0.0, current version 
6001.6.0)
    @executable_path/../Resources/lib/libgobject-2.0.0.dylib (compatibility version 6001.0.0, current version 
6001.6.0)
    @executable_path/../Resources/lib/libfribidi.0.dylib (compatibility version 0.0.0, current version 0.0.0)
    @executable_path/../Resources/lib/libharfbuzz.0.dylib (compatibility version 20504.0.0, current version 
20504.0.0)


What version of meson did pip install for you?
bash-3.2$ python -m pip show meson
Name: meson
Version: 0.51.2
Summary: A high performance build system
Home-page: http://mesonbuild.com
Author: Jussi Pakkanen
Author-email: jpakkane gmail com
License: Apache License, Version 2.0
Location: /Users/gtk3/.new_local/share/venv/etc-QjyTq6eG/lib/python3.6/site-packages
Requires:
Required-by:
A double slash doesn't matter.
Check the typelib with `strings path/to/bundle/Contents/Resources/lib/girepository-1.0/Pango-1.0.typelib | 
grep libpango`. It should also say @executable_path/../lib/libpango-1.0.0.dylib.
Hmm, it doesn't:

$ strings myapp.app/Contents/Resources/lib/girepository-1.0/Pango-1.0.typelib | grep libpango
libpango-1.0.0.dylib

Since you're using a launcher script, is the actual executable (e.g. python) in bundle/Contents/MacOS?
There are two executables: myapp and python3.6

To be clear, I'm not using the launcher shell script, but the compiled python-launcher.c and gtk_launcher.py 
files.
So the bundler didn't rerun gir-scanner and gir-compiler.

Oh, crud. I bet you cloned gtk-mac-bundler from GitHub instead of gitlab.gnome.org, I see that I have been 
pushing only to the latter one. I just got GitHub up to date, so if that's where you got it pull and bundle 
again.

My bash history showed I cloned from GitLab, not GitHub. I did a `git pull` and everything was already up to 
date. Just to be sure I removed gtk-mac-bundler and did a fresh clone/make install, but the error remains.

Can the error already happen earlier, during build perhaps? Since I already have to set the 
DYLD_FALLBACK_LIBRARY_PATH for just running the app without even bundling.
At the base it's because meson wants to use @rpath, see https://github.com/mesonbuild/meson/issues/3574. This 
led to https://gitlab.gnome.org/GNOME/gobject-introspection/issues/222.

Running in a jhbuild shell should get DYLD_LIBRARY_PATH set for you and that should get dlopen() to load the 
libraries/modules with basename-only paths in foo.typelib.
For your bundle, 
https://gitlab.gnome.org/GNOME/gtk-mac-bundler/commit/93edee7e2d0ec8230aaf5acb21452202b10cd678 is supposed to 
fix the paths in the Gir files to be @excutable_path/../Resources/lib/foo.dylib and then recompile the type 
libs. If you're sure you've got that commit and it's not working then we need to figure out why not.
Oh, one more puzzle-piece: You need to load the Gir files like this:

   <gir>
     ${prefix}/share/gir-1.0/*.gir
   </gir>

in your bundle file and not load the typelibs explicitly. I neglected to document that in the wiki, I'm doing 
so now.

We're a step closer. I added some print statements in that gtk-mac-bundler block of code to see if it really was being called and what it was doing. This showed that it was changing what's expected and fixed the paths. For example for Pango:

    transform file: /Users/gtk3/gtk/inst/share/gir-1.0/Pango-1.0.gir
    match line: shared-library="libpango-1.0.0.dylib"
    new line: shared-library="@executable_path/../Resources/lib/libpango-1.0.0.dylib"     typelib: /path/to/.myapp.app/Contents/Resources/lib/girepository-1.0/Pango-1.0.typelib

Checked the bundle file and I indeed have that <gir> block, but I also had the following line:

    <data>${prefix}/lib/girepository-1.0</data>

You know better, but my guess is that it replaced the fixed files with the originals again. Removing this line fixed the initial error. I'm not sure where I got this from. I might have taken different parts from different projects.

However another one pops up:

    objc[46154]: Class GNotificationCenterDelegate is implemented in both /Users/gtk3/gtk/inst/lib/libgio-2.0.0.dylib (0x10de41578) and /path/to/myapp.app/Contents/Resources/lib/libgio-2.0.0.dylib (0x10f23f578). One of the two will be used. Which one is undefined.
    Segmentation fault: 11

This is in the normal shell, not jhbuild shell. I'm not sure where it gets that local lib path from, there are no environment variables set to point there.

Timo


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]