Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle duplicate symbol error from 3rd party libraries?

I have two 3rd party libraries that seem to use the same class. That should be fine but I'm getting this type of error when building:

ld: duplicate symbol .objc_class_name_CJSONScanner in /Users/myappOne/TapjoyConnect/Frameworks/libTapjoyConnectSimulatorRewardInstall_Ads_Pinch.a(CJSONScanner.o) and /Developer/Projects/BuildOutput/Debug-iphonesimulator/OtherLibrary_d.a(CJSONScanner.o)

How can I handle this issue...

-- EDIT --

...if the source files are not available?

like image 219
user230949 Avatar asked May 26 '10 05:05

user230949


2 Answers

I'm going to assume that these are two third party libraries that have only provided you with the .a files and not the source code. You can use libtool, lipo and ar on the terminal to extract and recombine the files.

To see what architectures are in the file:

$ lipo -info libTapjoy.a
Architectures in the fat file: libTapjoy.a are: armv6 i386

Then to extract just armv6, for example:

$ lipo -extract_family armv6 -output libTapjoy-armv6.a libTapjoy.a
$ mkdir armv6
$ cd armv6
$ ar -x ../libTapjoy-armv6.a

You can then extract the same architecture from the other library into the same directory and then recombine them like so:

$ libtool -static -o ../lib-armv6.a *.o

And then finally, after you've done this with each architecture, you can combine them again with lipo:

$ cd ..
$ lipo -create -output lib.a lib-armv6.a lib-i386.a

This should get rid of any duplicate symbols, but will also combine the two libraries into one. If you want to keep them separate, or just delete the duplicate from one library, you can modify the process accordingly.

like image 138
Cory Kilger Avatar answered Sep 18 '22 14:09

Cory Kilger


Cory Kilger's answer is the right way to go ... just a minor tweak since I don't have the reputation to comment.

On my Mac OS 10.8 system, this lipo command is the one I used to make the .a files for use with ar:

lipo -thin armv6 -output libTapjoy-armv6.a libTabjoy.a

The man page for lipo says -extract and -extract_family both produce universal .a files and my ar command won't extract anything from them.

like image 40
David Smith Avatar answered Sep 19 '22 14:09

David Smith