Rparh issue on Qt macOS deployment

22 views Asked by At

I’m working on a CMake based cross-platform Qt project which uses embedded python interpreter to run my web api script using Python C API. With a help of CMake and macdeployqt, I’ve managed to deploy my application on macOS platform. Below you will see the file structure of my bundle:

└── Core.app
    └── Contents
        ├── Info.plist
        └── MacOS
            ├── Core
            ├── Client
            ├── python311
            │   ├── bin
            │   ├── include
            │   ├── lib
            │   └── share
            └── server
                ├── README.md
                └── src

Core, and Client are binary executables. server contains web api code and python311 is an embedded python package that contains whatever package needed to run the web server. This embedded python package linked to the Core executable.

When I deploy the app someone else can’t run it on their macOS system. otool output of the Core executable:

> otool -L Core
    @rpath/libpython3.11.dylib (compatibility version 3.11.0, current version 3.11.0)
    @rpath/QtWidgets.framework/Versions/A/QtWidgets (compatibility version 6.0.0, current version 6.5.2)
    @rpath/QtConcurrent.framework/Versions/A/QtConcurrent (compatibility version 6.0.0, current version 6.5.2)
    @rpath/QtCore.framework/Versions/A/QtCore (compatibility version 6.0.0, current version 6.5.2)
    @rpath/libsentry.dylib (compatibility version 0.0.0, current version 0.0.0)
    @rpath/QtGui.framework/Versions/A/QtGui (compatibility version 6.0.0, current version 6.5.2)
    /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 2299.50.120)
    /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/Metal.framework/Versions/A/Metal (compatibility version 1.0.0, current version 306.5.16)
    /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
    /System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1500.65.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.100.3)

On someone else’s computer, if I run the app from console, I got:

> ./Core
dyld[54987]: Library not loaded: @rpath/libpython3.11.dylib
  Referenced from: <B8A809D7-BFC4-3617-A918-2E7643B4B792> /Users/<current-pc>/Documents/Core.app/Contents/MacOS/Core
  Reason: tried: '/Users/<deployed-pc>/QtProjects/CoreApp/release/build/bundle/Core.app/Contents/MacOS/python311/lib/python3.11/libpython3.11.dylib' (no such file), 
'/Users/<deployed-pc>/QtProjects/CoreApp/release/build/bundle/Core.app/Contents/MacOS/python311/lib/python3.11/libpython3.11.dylib' (no such file), 
'/Users/<deployed-pc>/QtProjects/CoreProject/release/build/bundle/Core.app/Contents/MacOS/python311/lib/libpython3.11.dylib' (no such file), 
'/Users/<deployed pc user>/QtProjects/CoreApp/release/build/bundle/Core.app/Contents/MacOS/python311/lib/libpython3.11.dylib' (no such file), 
'/Users/<current-pc>/Documents/Core.app/Contents/MacOS/../Frameworks/libpython3.11.dylib' (no such file), 
'/Users/<deployed-pc>/QtProjects/CoreApp/release/build/bundle/Core.app/Contents/MacOS/python311/lib/python3.11/libpython3.11.dylib' (no such file), 
'/Users/<deployed-pc>/QtProjects/CoreApp/release/build/bundle/Core.app/Contents/MacOS/python311/lib/python3.11/libpython3.11.dylib' (no such file), 
'/Users/<deployed-pc>/QtProjects/CoreApp/release/build/bundle/Core.app/Contents/MacOS/python311/lib/libpython3.11.dylib' (no such file),
 '/Users/<deployed-pc>/QtProjects/CoreApp/release/build/bundle/Core.app/Contents/MacOS/python311/lib/libpython3.11.dylib' (no such file),
 '/Users/<current-pc>/Documents/Core.app/Contents/MacOS/../Frameworks/libpython3.11.dylib' (no such file),
 '/usr/local/lib/libpython3.11.dylib' (no such file), 
'/usr/lib/libpython3.11.dylib' (no such file, not in dyld cache)
[1]    54987 abort      ./Core

Seems like its not properly resolving the paths, maybe I am doing something wrong when linking the embedded python. Even if the python problem solved, I see the same problem on the next library that is linked to the Core executable: e.g. Qt libraries:

dyld[55997]: Library not loaded: @rpath/QtCore.framework/Versions/A/QtCore
  Referenced from: <E120D6AF-4911-32FB-A849-B9DFBC1AF87E> /Users/<current-pc>/Projects/CoreApp/build/bundle/Core.app/Contents/MacOS/Core
  Reason: tried: '/Users/<current-pc>/Projects/CoreApp/build/bundle/Core.app/Contents/MacOS/python311/lib/QtCore.framework/Versions/A/QtCore' (no such file), 
'/Users/<current-pc>/Projects/CoreApp/build/bundle/Core.app/Contents/MacOS/python311/lib/QtCore.framework/Versions/A/QtCore' (no such file), 
'/Library/Frameworks/QtCore.framework/Versions/A/QtCore' (no such file), 
'/System/Library/Frameworks/QtCore.framework/Versions/A/QtCore' (no such file, not in dyld cache)
[1]    55997 abort      ./Core

Using below CMake command in the root CMakeLists.txt of the target, strangely concatenates search paths of the executable:

set_target_properties(Core PROPERTIES
    INSTALL_RPATH "@executable_path/python311/lib"
    BUILD_WITH_INSTALL_RPATH TRUE
)

> ./Core
dyld[60096]: Library not loaded: @rpath/libpython3.11.dylib
  Referenced from: <E0EE54EF-E29A-3F1B-906A-57BF9F20276A> /Users/<current-pc>/Projects/CoreApp/build/bundle/Core.app/Contents/MacOS/Core
  Reason: tried: '/Users/<current-pc>/Projects/CoreApp/build/bundle/Core.app/Contents/MacOS/libpython3.11.dylib' (no such file), 
'/Users/<current pc user>/Projects/CoreApp/build/bundle/Core.app/Contents/Frameworks/libpython3.11.dylib' (no such file),
 '/Users/<current pc user>/Projects/CoreApp/build/bundle/Core.app/Contents/MacOS/libpython3.11.dylib' (no such file), 
'/Users/<current-pc>/Projects/CoreApp/build/bundle/Core.app/Contents/Frameworks/libpython3.11.dylib' (no such file),
 '/usr/local/lib/libpython3.11.dylib' (no such file), 
'/usr/lib/libpython3.11.dylib' (no such file, not in dyld cache)
[1]    60096 abort      ./Core

Any comments regarding this point are welcome, thank you!

0

There are 0 answers