Reputation: 6756
I have mac os x. I have application and it needs to use shared library (framework on mac), that is developed as separate project, but concurrently and in Qt 5 too.
App.pro
.
.
else:mac: LIBS += -F$$OUT_PWD/Frameworks -framework library1
.
.
QMAKE_RPATHDIR += /usr/lib
firstly, i am telling to qmake, that library1 will reside in it's bundle in Frameworks directory (this is no problem, linking is done success)
secondly, QMAKE_RPATHDIR
should tell to gcc compiler, that when app's libraries are located, it should look to those paths in QMAKE_RPATHDIR
too. I specified /usr/lib
, just to check if it will work, but:
otool -l app
doesn't show up any LC_RPATH
(i am expecting there will be one record for /usr/lib
) as in here Print rpath of executable on OSX
I really need to setup my development environment (Qt 5, Mac OS X, one base application, one core library (this will act's as SDK for plugins too) and additional plugins (shared libraries too).
ERROR is still:
dyld: Library not loaded: library1.framework/Versions/1/library1
Referenced from: /Users/Krab/projects/qtProjects/build-rootProject-Desktop_Qt_5_3_0_clang_64bit-Release/app/app.app/Contents/MacOS/app
Reason: image not found
this is obvious, because the settings in .pro
files is just for linking and doesn't resolve the dynamic loading of those libraries (which should be resolved by that QMAKE_RPATHDIR
directive).
Upvotes: 5
Views: 5505
Reputation: 5300
In my case, I had a simple dylib instead of a framework linked to my executable. I had the following already:
LIBS += -L/path-to-mylibrary/ -lmylibrary
QMAKE_RPATHDIR += /path-to-mylibrary/
QMAKE_RPATHDIR
was working as my executable listed the LC_RPATH
command correctly (obtained by otool -l myexecutable
):
Load command 25
cmd LC_RCPATH
cmdsize 56
name /path-to-mylibrary/ (offset 12)
However, my resulting executable listed the LC_LOAD_DYLIB
command for my library as follows:
Load command 12
cmd LC_LOAD_DYLIB
cmdsize 48
name libmylibrary.dylib (offset 24)
As per this answer, I updated the LC_LOAD_DYLIB
command to include the RPATH when looking for the dylib by adding the following to the .pro file of my executable application:
QMAKE_POST_LINK += install_name_tool -change libmylibrary.dylib @rpath/libmylibrary.dylib $$TARGET
Afterwards, my executable started listing the LC_LOAD_DYLIB
command correctly:
Load command 12
cmd LC_LOAD_DYLIB
cmdsize 56
name @rpath/libmylibrary.dylib (offset 24)
As a side note, mylibrary is actually a qml plugin deployed into /qt-install-root/qt-version/platform/qml/Mylibrary/
and is loaded also from the QML engine in other projects.
Upvotes: 0
Reputation: 763
Add
QMAKE_POST_LINK += install_name_tool -add_rpath <path to look in> $$TARGET
to your .pro file - where < path to look in> is the path you framework or dylib resides.
for example, if you place the framework right next to your executable, use
QMAKE_POST_LINK += install_name_tool -add_rpath @executable_path $$TARGET
Upvotes: 0
Reputation: 24190
You need to build your framework with the correct install name. For example:
QMAKE_LFLAGS_SONAME = -Wl,-install_name,@rpath/
Then in your application,
osx:LIBS += -F$$OUT_PWD/Frameworks -framework library1
QMAKE_RPATHDIR += /usr/lib
If your resulting "library1" framework is placed in /usr/lib, then your application should load fine. However, in almost all cases you'll want the framework placed inside your application bundle, like so:
myapp.app/Contents/Frameworks/library1.framework
In that case you'd set the rpath in your application a little differently, like so:
QMAKE_RPATHDIR += @executable_path/../Frameworks
Upvotes: 6