Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 10, 2008, 12:03 AM   #1
fabrizi0
macrumors newbie
 
Join Date: Apr 2008
Linker (ld) problems

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
fabrizi0 is offline   0 Reply With Quote
Old Apr 10, 2008, 04:07 AM   #2
lazydog
macrumors 6502a
 
Join Date: Sep 2005
Location: Cramlington, UK
Send a message via MSN to lazydog
Quote:
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.

Last edited by lazydog; Apr 10, 2008 at 09:41 AM.
lazydog is offline   0 Reply With Quote
Old Apr 10, 2008, 10:11 AM   #3
fabrizi0
Thread Starter
macrumors newbie
 
Join Date: Apr 2008
Quote:
Originally Posted by lazydog View Post
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
fabrizi0 is offline   0 Reply With Quote
Old Feb 17, 2009, 03:41 PM   #4
pld
macrumors newbie
 
Join Date: Feb 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?
pld is offline   0 Reply With Quote
Old Feb 18, 2009, 09:03 AM   #5
fabrizi0
Thread Starter
macrumors newbie
 
Join Date: Apr 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).

Fab
fabrizi0 is offline   0 Reply With Quote
Old Feb 18, 2009, 04:48 PM   #6
pld
macrumors newbie
 
Join Date: Feb 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: http://discussions.apple.com/thread....readID=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.
pld is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Mach-O Linker Error: Duplicate Symbols moonman239 iPhone/iPad Programming 5 Oct 21, 2013 09:08 PM
RMBP 15" - Problems problems and more problems rmwebs MacBook Pro 14 Sep 30, 2013 04:22 AM
Linker command failed with exit code 1 adildacoolset iPhone/iPad Programming 2 Feb 15, 2013 06:00 AM
Linker Command Failed Error, Please Help loon3y iPhone/iPad Programming 2 Sep 26, 2012 05:20 PM
Linker Command Failed With Exit Code 1? loon3y iPhone/iPad Programming 2 Sep 5, 2012 06:10 PM

Forum Jump

All times are GMT -5. The time now is 06:51 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC