Results 1 to 7 of 7

Thread: Mac linking to .dylib (resolving symbols @link time)

  1. #1
    Join Date
    Jan 2006
    Location
    Earth (Terra)
    Posts
    87
    Thanks
    4
    Thanked 6 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Mac linking to .dylib (resolving symbols @link time)

    Well, it's been a while since I worked on Mac, and that was in the Carbon days.

    So, I've created a nice little utility library (.dylib) and it looks fine. otool -D produces this:

    Qt Code:
    1. libGenQtSupportLib.so.dylib:
    2. libGenQtSupportLib.so.1.dylib
    To copy to clipboard, switch view to plain text mode 

    so that looks nice, and the otool -L produces this:

    Qt Code:
    1. libGenQtSupportLib.so.1.dylib (compatibility version 1.0.0, current version 1.0.0)
    2. @rpath/QtWidgets.framework/Versions/5/QtWidgets (compatibility version 5.6.0, current version 5.6.0)
    3. @rpath/QtGui.framework/Versions/5/QtGui (compatibility version 5.6.0, current version 5.6.0)
    4. @rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.6.0, current version 5.6.0)
    5. /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
    6. /System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility version 1.0.0, current version 1.0.0)
    7. /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
    8. /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
    To copy to clipboard, switch view to plain text mode 

    and I think that looks ok. I'm not sure what the @rpath is, though...

    So, now I'm trying to link to it, and the linker claims it can't find the library:

    Here's the relevant part of my application .pro:

    Qt Code:
    1. QT += core gui
    2.  
    3. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    4.  
    5. QMAKE_CXXFLAGS += "-std=c++11 -D__TESTING__"
    6. QMAKE_CXXFLAGS_DEBUG += -O0
    7.  
    8. QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.7
    9.  
    10. TARGET = configPropertiesBundler
    11. TEMPLATE = app
    12.  
    13. CONFIG += debug
    14.  
    15. GENQTSUPPORTLIBDIR = $$(DEV)/Qt/GenQtSupportLib
    16.  
    17. INCLUDEPATH += $${GENQTSUPPORTLIBDIR}
    18.  
    19. LIBS += -l$${GENQTSUPPORTLIBDIR}/libGenQtSupportLib.so.dylib
    To copy to clipboard, switch view to plain text mode 

    What looks like the 'ld' command in the 'compile output' window is here:

    Qt Code:
    1. /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names
    2. -stdlib=libc++ -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk
    3. -mmacosx-version-min=10.7 -Wl,-rpath,/Users/Shared/devtools/qt5r/lib -o configPropertiesBundler.app/Contents/MacOS/configPropertiesBundler
    4. main.o mainwindow.o OpenPropertiesBundleDialog.o moc_mainwindow.o moc_OpenPropertiesBundleDialog.o
    5. -F/Users/Shared/devtools/qt5r/lib
    6. ---> -l/Users/Shared/dev/Qt/GenQtSupportLib/libGenQtSupportLib.so <-----
    7. -framework QtWidgets -framework QtGui -framework QtCore -framework OpenGL -framework AGL
    To copy to clipboard, switch view to plain text mode 

    (note that my support lib name is truncated to '.so' without the '.dylib')

    And the error output is:

    Qt Code:
    1. ld: library not found for -l/Users/Shared/dev/Qt/GenQtSupportLib/libGenQtSupportLib.so
    2. clang: error: linker command failed with exit code 1 (use -v to see invocation)
    To copy to clipboard, switch view to plain text mode 

    ... which is probably correct, given that it's looking for a '.so', even though I specified a '.so.dylib'

    So, what am I missing? I'm sure the path is correct - the lib is really there. I've tried both the -L<path> -l<shortname> and the -l<fullname> variants and still get the same issue.

    I guess I could create a '.so' link to the .dylib so it would find it, but that doesn't seem very proper.

    (Note the question is re: link-time/symbol resolution time, not run-time.)

    Any thoughts appreciated.

    rickb

  2. #2
    Join Date
    Jan 2006
    Location
    Earth (Terra)
    Posts
    87
    Thanks
    4
    Thanked 6 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Mac linking to .dylib (resolving symbols @link time)

    Well, if I create a link '.so' without the .dylib extension to the .dylib (and use the -L<libpath> -l<libname> convention), it works.

    Not getting the mac-specific lib naming convention correct.
    Last edited by rickbsgu; 3rd March 2016 at 18:54.

  3. #3
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Mac linking to .dylib (resolving symbols @link time)

    The dynamic libraries I have built/used on OSX just have the dylib extension, so for example, a library named Recode: /path/to/library/libRecode.dylib, I would use:
    Qt Code:
    1. LIBS = -L /path/to/library -l Recode
    To copy to clipboard, switch view to plain text mode 
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  4. #4
    Join Date
    Jan 2006
    Location
    Earth (Terra)
    Posts
    87
    Thanks
    4
    Thanked 6 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Mac linking to .dylib (resolving symbols @link time)

    Precisely - and that makes perfect sense, except that it's not working. It's looking for a '.so'

    It's like it doesn't know it's on a mac. The QMAKESPEC variable is 'macx-clang', so that seems correct.

    Might be my Qt build. I built in two separate locations - one for release (mainly for QtCreator) and one for debug (with the --developer switch turned on). Maybe I need to rebuild with 'debug-and-release' so that the debug libs have the '_debug' suffix and qt works better (at finding libs, anyway...)

    Sigh. Would rather QtCreator didn't use my build libs. I can shove the current release libs into the QtCreator bundle so that it's standalone, I guess, & doesn't rely on my build libs... Kind of a PITA...
    Last edited by rickbsgu; 4th March 2016 at 17:44.

  5. #5
    Join Date
    Jan 2006
    Location
    Earth (Terra)
    Posts
    87
    Thanks
    4
    Thanked 6 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Mac linking to .dylib (resolving symbols @link time)

    Didn't have time to figure this out earlier, but now have re-focused attention on it, and...

    ...per usual, something dumb.

    First some good news: the QtCreator build actually does install the needed frameworks in the bundle, so it is standalone and nothing needs to be done to make it so. That's good, in case I want to tweak the qt build and not affect qtc.

    The issue: in my support lib .pro, I specified <libname>.so as the target. Which threw off the default library search mechanism. There is probably some permuted name I could use to get it, but the real answer is to just specify <libname> as the target, without the '.so' - and the normal resolution mechanism works fine.

    So, I didn't really need to do the frameworks build, but I did, anyway. Might as well.

    Onward...

  6. #6
    Join Date
    Jan 2006
    Location
    Earth (Terra)
    Posts
    87
    Thanks
    4
    Thanked 6 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Mac linking to .dylib (resolving symbols @link time)

    Quote Originally Posted by rickbsgu View Post
    First some good news: the QtCreator build actually does install the needed frameworks in the bundle, so it is standalone and nothing needs to be done to make it so. That's good, in case I want to tweak the qt build and not affect qtc.
    No it doesn't. bleah... banging along...

  7. #7
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Mac linking to .dylib (resolving symbols @link time)

    macdeployqt is what I use to embed the Qt framework libraries and plugins into my application bundles. Have you tried that?
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

Similar Threads

  1. [MSVC 2010] Static linking and unresolved external symbols
    By Blood9999 in forum Qt Programming
    Replies: 12
    Last Post: 31st December 2014, 21:12
  2. Replies: 0
    Last Post: 11th August 2011, 16:43
  3. How to link against a libqjpeg_debug.dylib?
    By Alex_123 in forum Installation and Deployment
    Replies: 2
    Last Post: 24th May 2009, 10:54
  4. problem in linking with libqtiff.dylib
    By nareshqt in forum Qt Programming
    Replies: 1
    Last Post: 20th June 2008, 13:19
  5. Linking problems with multiply defined symbols
    By JimBrown in forum Qt Programming
    Replies: 5
    Last Post: 2nd March 2007, 16:48

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.