XCode static library linking ld error

Joined
Oct 10, 2008
Messages
2
Reaction score
0
Points
1
Hi,

I am trying to link a static library written by me and compiled with gcc (libtest.a) with XCode 3.1 project. After writing the library, I dragged the library file to the Frameworks folder as I've been doing previously.

But now whenever I call a function from the library( int myFuction( int ) ) and build the project I get the following ld error:

ld warning: in /Users/dev/lib/libtest.a, file is not of required architecture

Undefined symbols:
"_myFunction", referenced from:
_test_Function in mytest.o
ld: symbol(s) not found
collect2: ld returned 1 exit status


It seems that lib file is being located properly but for some reason ld can't find symbols in the file. Anyone have any idea how I go about fixing this problem? Help will be appreciated.


--
Thanks,
Salman
 
Joined
Jun 25, 2005
Messages
3,231
Reaction score
112
Points
63
Location
On the road
Your Mac's Specs
2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
file is not of required architecture

If I was to guess, I'd say that part sounds like you have compiled it for the opposite architecture from what you are compiling the the calling code for.
 
OP
M
Joined
Oct 10, 2008
Messages
2
Reaction score
0
Points
1
If I was to guess, I'd say that part sounds like you have compiled it for the opposite architecture from what you are compiling the the calling code for.

I figured that out :Not-Amused:

Well, actually I forgot to mention that I compiled this file with the arm-apple-darwin-gcc compiler (cross compiling) and the XCode project is for iPhone as well.

Isn't compiling the file using the arm-apple-darwin-gcc and XCode one and the same thing. Don't they have the same architecture?
 
Joined
Nov 5, 2008
Messages
1
Reaction score
0
Points
1
you need to add -dynamiclib flag

To fix the error, add the "-dynamiclib" flag.
Something like: gcc -dynamiclib *.c -o libmylibname.dylib
You can find more at:
<http://developer.apple.com/documentation/DeveloperTools/Conceptual/DynamicLibraries/Articles/CreatingDynamicLibraries.html#//apple_ref/doc/uid/TP40002073>

or for me it works like this.

g++ -dynamiclib -undefined dynamic_lookup -single_module -o libBlah.dylib *.o
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top