Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

fabrizi0

macrumors newbie
Original poster
Apr 9, 2008
3
0
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:
/usr/local/lib/libfoo.a
/usr/local/lib/libbar.a
/usr/local/lib/libfoo++.a
/usr/local/lib/libbar++.a

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

Interested?
If you want to reproduce it, download the xmlrpc-c library from Sourceforge
(xmlrpc-c.sourceforge.net), 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.
Fab
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
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

Hi

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.
 

fabrizi0

macrumors newbie
Original poster
Apr 9, 2008
3
0
Hi

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.


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

Fab
 

pld

macrumors newbie
Feb 11, 2009
5
0
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?
 

fabrizi0

macrumors newbie
Original poster
Apr 9, 2008
3
0
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).

Fab
 

pld

macrumors newbie
Feb 11, 2009
5
0
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: http://discussions.apple.com/thread.jspa?threadID=1713972

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.