Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
A Font Problem RobertsonDesign Mac Basics and Help 3 Nov 7, 2010 06:30 PM
Macbook pro 15" i7 problems, need some help. filfortugno MacBook Pro 1 Nov 7, 2010 05:44 PM
Major AppleTV (2010) problems all of a sudden. iMJustAGuy Apple TV and Home Theater 6 Nov 6, 2010 08:57 AM
2007 Macbook wifi connection problems jwbradle MacBook 2 Nov 3, 2010 01:35 PM
Linking (ld) problems (g++) joakimk Mac Programming 0 Jun 25, 2007 02:04 AM


All times are GMT -5. The time now is 03:46 AM.

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

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