4

I am using 2 third party libraries in my iPad app. The source code for these libraries are not known to me. These libraries have the functions with same name in both. So I am are getting "Apple Mach - O (id) error" because of the collision in function names. I cant change the function names within them, as source code is not known. On building the app the error are occurring.

The error states that:

ld: duplicate symbol _T_strcpy in /Users/Desktop/untitled folder/Universal/lib/simulator/myLib.a(mem.o) and /Users/Library/Developer/Xcode/DerivedData/iOS-aqpprpcivvjjadbsutqqmtjsoczk/Build/Intermediates/ios.build/Debug-iphonesimulator/myApp iPad.build/Objects-normal/i386/pdcrypte2.o for architecture i386 collect2: ld returned 1 exit status Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-g++-4.2 failed with exit code 1

Can anybody share some suggestions??

Cyprian
  • 9,423
  • 4
  • 39
  • 73
Rio J
  • 51
  • 1
  • 2
  • One thing for sure is that whoever created those static libraries did not follow the right design patterns. All the classes should have a specific prefix to avoid situations such as yours. Don't think you can do anything about it. – Cyprian Aug 04 '11 at 07:19
  • Possible duplicate: http://stackoverflow.com/questions/6925609/how-to-include-static-libraries-which-have-same-names-for-object-files-within-the. Even the name of temporary build folder is equal (xxx/iOS-aqpprpcivvjjadbsutqqmtjsoczk/xxx) – Kay Aug 04 '11 at 07:36
  • @Cyprian: It could be some plain C libraries, written by some careless student, assistant or even (*sic*) professor (this is apparently a University project). – datenwolf Aug 04 '11 at 10:04

1 Answers1

6

You're pretty much screwed. The creators of the original libraries failed one of the most basic rules of library development: Prepend all your exported symbols with a library specific prefix, to avoid namespace collisions.

Your only way out is to wrap each and every function from each library with a wrapper that has a namespace prefixed name, statically link the library to the wrapper and strip all not exported symbols. Then use the wrapper libraries and symbol names.

Actually if the libraries are static you can fix this issue: How to deal with symbol collisions between statically linked libraries?

Community
  • 1
  • 1
datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Thanks for the response.. Hoe to create wrapper for each and every function within the library? – Rio J Aug 04 '11 at 08:01
  • @Rio J: Well, by writing it: For each function in the library you use write a small trampoline function of the same signature forwards the function call -- Actually the most concise way to wrap this would be rewriting the symbols in the libraries symbol table. However you will then have to adjust each and every symbol in the header files, too, of course (nothing a large bunch of #define statements in a pre-included helper header can't solve). – datenwolf Aug 04 '11 at 08:54
  • I am, however not aware of such a specialized symbol table manipulation tools. Though disassembling the library, using sed to edit the symbol names and reassembling it does the trick, very well indeed. In the same step you could also auto generate the rewriting header file. – datenwolf Aug 04 '11 at 08:56
  • 1
    I just found out that the `objcopy` utility provides an option to prefix all symbols with a custom string. So you could first dump all symbols with `nm` write the #define prefixing header, then objcopy --prefix-symbols=${LIBRARY_NAME} – datenwolf Aug 04 '11 at 09:26
  • I wil try to do that datenwolf. Can you provide some sample code for the same? – Rio J Aug 04 '11 at 10:10
  • @Rio J: I just wrote some article about this, which I posted as self answered question on SO: http://stackoverflow.com/questions/6940384/how-to-deal-with-symbol-collisions-between-statically-linked-libraries/6940389#6940389 – datenwolf Aug 04 '11 at 11:15