Linking an objective-c lib on OS X



  • Hi,

    I have a Qt gui app for OS X (macx-clang) and a third-party static lib (.a) that was made with objective-c. I don't have access to the lib source, only the headers.

    I can't seem to link with this lib. Any of the lib's functions referenced from the app result in "unknown symbols for architecture x86_64". I've verified that the lib is x86_64 and that it was built with the same version of Clang that we're using. I assume the issue is that it's an obj-c lib.

    I found references in the docs for including mm files but I don't have the source, only the lib and headers. What must I do in order to use the lib successfully?

    Thanks!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Can you show how you setup the linking to that library ?



  • Thank you.

    Like any other static lib:
    LIBS += $$PWD/libs/problematicLib.a

    Which results in...
    Undefined symbols for architecture x86_64:
    "functionName(param)", referenced from blah

    ... for any function I try to pull in from that lib.



  • Hi, it looks like you've been bitten by the "changing c++ standard library" syndrome. In OSX 10.9 Apple changed from using libstdc++ to libc++ so most likely your Qt app is built to use libc++ but that third-party static lib is older and built using libstdc++, that's why you get those errors.

    Easiest I think is to tell Qt to build your app in the old way, try inserting CXXFLAGS = -stdlib=libstdc++ in your .pro file. There are plenty of discussions of this, for example here and here


  • Lifetime Qt Champion

    To add to @hskoglund, how are you calling these function exactly ?



  • @hskoglund, both the lib and Qt were built with the same version of Clang (clang-703.0.31). stdlib symbols don't appear to be the problem.

    @SGaist, like anything else: include header, call function.



  • Just guessing, but if that library was built with Objective-C, and because usually Qt is built as Objective-C++ (i.e. .mm files instead of .m files), perhaps you need to include extern "C" { in the header file for that lib.


  • Lifetime Qt Champion

    The syntax of Objective-C is not the same as pure C/C++ hence my question. Are you calling them correctly ?



  • QMAKE_LFLAGS += -ObjC

    ^^ very important

    Thanks all, working fine now.


Log in to reply
 

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