@rpath issues with Qt 5.5/OSX in debug mode



  • Qt Creator 3.5.1 (opensource)
    Based on Qt 5.5.1 (Clang 6.1 (Apple), 64 bit)
    
    Built on Oct 15 2015 01:54:05
    
    From revision b4c52505ca
    

    My app runs fine in Release mode. But when I try to debug it in Debug mode, I get the following dynamic linking error:

    Debugging starts
    dyld: Library not loaded: @rpath/QtCore.framework/Versions/5/QtCore
      Referenced from: /Users/andy/build-cavewhere-Desktop_Qt_5_5_1_clang_64bit-Debug/qtc_Desktop__e049b762-debug/install-root/Cavewhere.app/Contents/MacOS/Cavewhere
      Reason: image not found
    

    I dug around enough to figure out what @rpath is and see that in Qt 5.5, a change was made to use absolute rpath to Qt libraries for non-prefix builds.

    I also used otool -l | grep LC_RPATH to determine that no rpaths are getting inserted into my debug binary.

    Mystifyingly, the release binary doesn't have any LC_RPATH commands either and reports the same error when I try to run it from finder or the console -- yet when I run it from Qt, Qt seems to work some unknown magic to give it an rpath.

    Is this a Qt 5.5 bug?
    Does anyone know a workaround?

    I tried cloning my kit (Desktop Qt 5.5.1 clang 64bit) and adding the following to the platform linker flags: -rpath /Users/andy/Qt/5.5/clang_64/lib, but it didn't make any difference and I didn't find any LC_RPATH commands in binaries built with that kit either.



  • Hi, normally with 5.5 you'll get an LC_RPATH inserted automagically by Qt Creator, both for release and debug builds. But it seems your project has a Qbs profile, maybe try rebuilding with a fresh profile?



  • @hskoglund Thanks for your response! It is a Qbs project, but how can I use a fresh profile? I don't see the option to create or select a different profile for a given kit in the Qbs section of the preferences.

    And how is it that Qt can run the release build even though the release build doesn't contain an LC_RPATH?



  • Hi, re. starting afresh in Qbs, have to get back to you on that :-) I'm a Qbs noob

    Re. Qt Creator launching your app without any LC_RPATH, for example it can instead export the path using an environment variable, e.g.
    export DYLD_FRAMEWORK_PATH=/Users/andy/Qt/5.5/clang_64/lib



  • @hskoglund Qt seems to have automatically put a correct DYLD_FRAMEWORK_PATH in the build/run environment. Are you sure it would get used whenever the frameworks are linked with @rpath though?



  • Hmm, normally Qt shouldn't mess with DYLD_FRAMEWORK_PATH but Qbs perhaps does it.
    When both @rpath and DYLD_FRAMEWORK_PATH are set, they are concatenated to each other in the list, i.e. when OSX loads frameworks it uses both of them.



  • @hskoglund are you sure the OSX loader can use the DYLD_FRAMEWORK_PATH in the @rpath list? The dyld man page indicates only one way to add something to the @rpath list -- LC_RPATH commands. It doesn't say anything about @rpath working with DYLD_FRAMEWORK_PATH.



  • I tested this way:

    1. Made a copy of my Qt installation in /Users/henry/Qt to /Users/henry/QtCopy
    2. Deleted the QtCore.framework directory from /Users/henry/Qt/5.5/clang64/lib
    3. Tried to launch a Qt simple app. No good, error is: "dyld: Library not loaded: @rpath/QtCore.framework/Versions/5/QtCore"
    4. Started a Terminal, typed:
      export DYLD_FRAMEWORK_PATH=/Users/henry/QtCopy/5.5/clang64/lib
    5. Tried to launch the same app. Works now. (Also checked with lsof -c appname that all of the framework DLLs are loaded from Qt but QtCore is loaded from QtCopy.)

    Note that this DYLD_FRAMEWORK_PATH exporting stunt does not work for locating the platform plugin dll libqcocoa.dylib, Qt still looks for it in the usual places, i.e. the hardwired path in QtCore, a qt.conf file etc.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.