Linker (ld) problems

Discussion in 'Mac Programming' started by fabrizi0, Apr 9, 2008.

  1. fabrizi0 macrumors newbie

    Apr 9, 2008
    I'm having a weird problem with the linker I cannot explain. Before filing it as a possible bug, I'd like to have your opinion on that.

    Brief description:
    I'm building an executable (command-line) that requires some external libraries.
    Let's say I need to link (statically) with:

    The external libraries (are given (to ld) by XCode using the form:
    -lfoo -lbar -lfoo++ -lbar++

    The problem: ld reports a bunch of unresolved symbols.

    If I invoke by hand ld by specifying the static libs directly as input files instead of libraries everything works fine:
    ld ... /usr/local/lib/libfoo.a /usr/locallib/libbar.a /usr/local/lib/libfoo++.a /usr/local/lib/libbar++.a

    If you want to reproduce it, download the xmlrpc-c library from Sourceforge
    (, build it and install it under /usr/local and try to build one of the example first using the form that uses the -l<lib> flag, and then with the other form.

    In my case I also discovered that ONLY ONE library needs to be listed using /usr/local/lib/<blah>.a...

    To be more specific, this is *NOT* working:
    ld <...> -lxmlrpc++ -lxmlrpc_server_abyss++ -lxmlrpc_server++ -lxmlrpc_server_abyss -lxmlrpc_server -lxmlrpc_abyss -lxmlrpc_util -lxmlrpc_xmlparse -lxmlrpc_xmltok -lxmlrpc

    and this IS WORKING:
    -lxmlrpc++ -lxmlrpc_server_abyss++ -lxmlrpc_server++ -lxmlrpc_server_abyss -lxmlrpc_server -lxmlrpc_abyss -lxmlrpc_util -lxmlrpc_xmlparse -lxmlrpc_xmltok /usr/local/lib/xmlrpc.a

    Weird isn't it?
    Am I missing something?
    Is it really a bug ?

    Thanks for your opinion.
  2. lazydog macrumors 6502a

    Sep 3, 2005
    Cramlington, UK

    I may be totally wrong here but, but it looks you only need /usr/local/lib/xmlrpc.a for linking. The -lx is shorthand for /usr/local/lib/libx.a. So looking at the two examples, the first is linking to non existing libraries, while the second is linking to /usr/local/lib/xmlrpc.a.

    b e n

    EDIT: It just occurred to me that the 1st line doesn't work because it's trying to link to /usr/local/lib/libxmlrpc.a which doesn't exist, hence the reason why the 2nd line works.
  3. fabrizi0 thread starter macrumors newbie

    Apr 9, 2008

    My bad... In my second example I was meant to put /usr/local/lib/libxmlrpc.a

    Right now I have my Xcode project that list all the external library in the project, *BUT* the libxmlrpc.a is listed in the "Other linker flags"...

    In conclusion it really seems to me the linker is really doing something wrong...

  4. pld macrumors newbie

    Feb 11, 2009
    fabrizi0, did you ever get this resolved? I am trying to port some existing code that makes fine under Solaris and Linux, but I am getting similar linker errors. What did you ever figure out?
  5. fabrizi0 thread starter macrumors newbie

    Apr 9, 2008
    Well, I have not tried to re-use the same feature as I have found a workaround.
    Instead of listing the libraries in the project, I'm adding (manually) all my dependencies to the linker command line, through the line "Other Linker Settings".
    This solution not only fixes my problem, but it also allow me to specify different libraries for different configuration (Debug/Release).

  6. pld macrumors newbie

    Feb 11, 2009
    We found our problem; one of our libraries happens to have the same name as a system library and ld for MacOS apparently searches for libraries differently than Solaris and Linux. Here is a link to another forum that gives some info:

    We resolved our problem by renaming our library. Since we are trying to maintain the same source and build process across multiple platforms, this was the easiest and most universal solution.

    Thanks for your help.

Share This Page