PDA

View Full Version : dynamic linking on mac



munna
28th December 2006, 14:44
Hi,

I have successfully compiled some Qt application on a mac and now i want to distribute it.
I am linking dynamically to the Qt library. I followed the instructions given here (http://doc.trolltech.com/qq/qq09-mac-deployment.html) and it works fine on system that has Qt installed on it. But when i try to execute the application on a system that does not have Qt installed I get the following error.




MyApplication has exited due to signal 5 (SIGTRAP).
[Session started at 2006-12-28 16:46:42 +0530.]
dyld: Library not loaded: libqt-mt.3.dylib
Referenced from: /Applications/MyApplication/Release/MyApplication.app/Contents/MacOS/MyApplication
Reason: image not found



Can someone please tell me how can I link my application to the Qt library so that it loads dynamically whenever the application wants ?

Thanks a lot.

jwintz
31st December 2006, 12:23
Everything's here : linking-the-application-to-qt-as-frameworks (http://doc.trolltech.com/4.2/deployment-mac.html#linking-the-application-to-qt-as-frameworks).

Hint : list your frameworks in a Makefile variable and do something like:



for f in $(QT_FRAMEWORKS); do \
ditto -rsrc "$(QTDIR)/lib/$$f.framework" ... ; \
rm debug ... ; \
rm headers ... ; \
install_name_tool -id ... ; \
for g in $(QT_FRAMEWORKS); do \
install_name_tool -change ... ; \
done; \
install_name_tool -change ... ; \
done


Be carefull, you'll have to list the framework in the right order (regarding which frameworks they rely on ...). Use otool -L to know which libraries a framework is linked with.

Example :



QT_FRAMEWORKS=QtCore QtXml QtNetwork QtGui QtSql Qt3Support QtOpenGL

Brandybuck
31st December 2006, 20:24
Here's a shell script I created to do all the Mac deployment dirty work for me, including making a dmg image. The usage is quite simple, all it needs is the name of the Qt application. It assumes makefile use (macx-g++ makespec), but it's a simple matter to adjust it to XCode use. It doesn't handle plugins and multiple executables, but that's not too common.

Enjoy.

jwintz
1st January 2007, 12:14
Very nice script.

Just be careful with the 'strip' thing: if someone adds plugin support to the script and if the latter take advantage of dynamic lookup, strip will cause lots of problems by removing useful symbols ;-)

This tip may save a lot of time.

Brandybuck
1st January 2007, 19:39
Yes, I know about the problems with plugins and "strip". Unfortunately, the Mac produces HUGE executables (even if they aren't universal).