Osx dylib



  • I am trying to deploy a osx qt app that uses a dylib also created with Qt. Both use OpenGL.

    In my application .pro file I have the following to copy it into the app folder for debugging:

    @
    macx {
    LIBS += ../mylib/mylib-build-desktop/mylib.dylib

    PRE_TARGETDEPS = ../mylib/mylib-build-desktop/mylib.dylib

    mylib.path = Contents/MacOS
    mylib.files = ../mylib/mylib-build-desktop/mylib.1.dylib
    QMAKE_BUNDLE_DATA += mylib
    }
    @

    This copies mylib into the app folder and I can debug just fine.

    Now, when I go to deploy the app using macdeployqt and try to run the resulting app I get the error that mylib.dylib was not found. It tried to reference it within the Frameworks folder. I think, OK; I'll just move it into the Frameworks folder. But NOW what happens is that I get an error saying mylib.dylib can not find OpenGL which is also in the same directory.

    Here is the error when the dylib is in the MacOS folder:

    @
    Dyld Error Message:
    Library not loaded: @executable_path/../Frameworks/mylib.dylib
    Referenced from: /Users/me/Test/MyApp.app/Contents/MacOS/MyApp
    Reason: image not found
    @

    And here is the error when I move it to Frameworks:

    @
    Dyld Error Message:
    Library not loaded: QtOpenGL.framework/Versions/4/QtOpenGL
    Referenced from: /Users/me/Test/MyApp.app/Contents/MacOS/../Frameworks/mylib.dylib
    Reason: image not found
    @

    The errors btw I only get on machines where I do not have the development tools installed, namely Qt.

    I've been banging my head on this for weeks, any help would be greatly appreciated. Thanks.

    -=ben



  • I think you have to change to deps in your "mylib" then. Look for the "install_name_tool" on how to do this.



  • Is QtOpenGL.framework (it's actually a directory!) present in MyApp.app/Contents/Frameworks?

    Else, install_name_tool is a good option to change the path to a path relative to the executable.



  • Yes, the QtOpenGL.framework tree is there.

    Here is an otool dump of mylib:

    @mylib.dylib:
    mylib.dylib (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/OpenAL.framework/Versions/A/OpenAL (compatibility version 1.0.0, current version 1.0.0)
    QtOpenGL.framework/Versions/4/QtOpenGL (compatibility version 4.6.0, current version 4.6.3)
    QtGui.framework/Versions/4/QtGui (compatibility version 4.6.0, current version 4.6.3)
    QtCore.framework/Versions/4/QtCore (compatibility version 4.6.0, current version 4.6.3)
    /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)
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
    /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 103.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.10)
    @

    It looks like it is trying to reference OpenGL from the current directory as well as from the /System folder. Am I right in that I need to remove the /System instance and change the other one to this: @executable_path/../Frameworks/QtOpenGL.framework/Versions/4/QtOpenGL ?

    Thanks.

    -=ben



  • Yep, that should do the trick!



  • Before trying that I found I can also add to my shared lib project as referenced here http://doc.qt.nokia.com/4.7-snapshot/mac-differences.html

    @QMAKE_LFLAGS_SONAME = -Wl,-install_name,@executable_path/../Frameworks/@

    Then in my app I copy the lib to the Frameworks folder instead of the MacOS folder. When I do this after I run macdeployqt it moves mylib.dylib from the Frameworks folder into the MacOS folder??? Why would it do that? Also it still looks like this will not get me away from having to use install_name_tool as the doc seems to suggest.

    Anyway.. I tried removing the /System references from mylib with otool but I think I am not doing something correct, here is what I tried and the error I get:

    @>install_name_tool -delete_rpath /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL mylib.dylib
    install_name_tool: no LC_RPATH load command with path: /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL found in: mylib.dylib (for architecture i386), required for specified option "-delete_rpath /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL"
    @

    Thanks.

    -=ben



  • I tried leaving the /System paths and changing the others to use the executable_path, and guess what? It worked!! :D

    Here is the resulting otool output:

    @ibi360.1.dylib:
    mylib.dylib (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/OpenAL.framework/Versions/A/OpenAL (compatibility version 1.0.0, current version 1.0.0)
    @executable_path/../Frameworks/QtOpenGL.framework/Versions/4/QtOpenGL (compatibility version 4.6.0, current version 4.6.3)
    @executable_path/../Frameworks/QtGui.framework/Versions/4/QtGui (compatibility version 4.6.0, current version 4.6.3)
    @executable_path/../Frameworks/QtCore.framework/Versions/4/QtCore (compatibility version 4.6.0, current version 4.6.3)
    /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)
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
    /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 103.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.10)
    @

    This was not straight forward but I feel I am getting a little further. Thanks again for your help.

    -=ben


Log in to reply
 

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