Results 1 to 5 of 5

Thread: dynamic linking on mac

  1. #1
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default dynamic linking on mac

    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 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.

  2. #2
    Join Date
    Apr 2006
    Posts
    29
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: dynamic linking on mac

    Everything's here : linking-the-application-to-qt-as-frameworks.

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

    Qt Code:
    1. for f in $(QT_FRAMEWORKS); do \
    2. ditto -rsrc "$(QTDIR)/lib/$$f.framework" ... ; \
    3. rm debug ... ; \
    4. rm headers ... ; \
    5. install_name_tool -id ... ; \
    6. for g in $(QT_FRAMEWORKS); do \
    7. install_name_tool -change ... ; \
    8. done; \
    9. install_name_tool -change ... ; \
    10. done
    To copy to clipboard, switch view to plain text mode 

    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 Code:
    1. QT_FRAMEWORKS=QtCore QtXml QtNetwork QtGui QtSql Qt3Support QtOpenGL
    To copy to clipboard, switch view to plain text mode 
    Last edited by jwintz; 31st December 2006 at 11:28.

  3. The following user says thank you to jwintz for this useful post:

    munna (1st January 2007)

  4. #3
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: dynamic linking on mac

    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.
    Attached Files Attached Files

  5. The following user says thank you to Brandybuck for this useful post:

    munna (1st January 2007)

  6. #4
    Join Date
    Apr 2006
    Posts
    29
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: dynamic linking on mac

    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.

  7. #5
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: dynamic linking on mac

    Yes, I know about the problems with plugins and "strip". Unfortunately, the Mac produces HUGE executables (even if they aren't universal).

Similar Threads

  1. static & dynamic linking
    By mickey in forum General Programming
    Replies: 6
    Last Post: 11th June 2010, 08:57
  2. Switching static to dynamic ui loading
    By s_a_white in forum Newbie
    Replies: 4
    Last Post: 26th June 2006, 15:57
  3. Dynamic grid layout
    By eriwik in forum Qt Programming
    Replies: 1
    Last Post: 12th June 2006, 15:19
  4. Replies: 4
    Last Post: 20th February 2006, 09:11
  5. Runtime dynamic linking + Qt4 problem
    By _Ramirez_ in forum Qt Programming
    Replies: 5
    Last Post: 11th February 2006, 14:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.