问题
I am developing an iPad app in which I have included 2 third party static libraries. The names of the object files in these 2 libraries are same. On building the app I am getting
"Apple Mach -O (id) error"
because of the same names of the object files in those 2 libraries. How to solve this problem?
Error looks like:
ld: duplicate symbol _T_strcpy in /Users/indiait-supportservices/Desktop/untitled folder/Universal/lib/simulator/libSecurIDLib.a(mem.o) and /Users/indiait-supportservices/Library/Developer/Xcode/DerivedData/ReceiverForiOS-aqpprpcivvjjadbsutqqmtjsoczk/Build/Intermediates/ReceiverForiOS.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.
回答1:
Are you building for one architecture? If you are building for multiple architectures and use the -all_load linker flag, this breaks the linker's ability to ignore symbols that are defined for multiple architectures. As a test, try building just for armv6 and see if the error goes away.
There is a good blog post here and a similar question discussed here.
Finally, you can add the following env var to debug problems with overriding categories:
OBJC_PRINT_REPLACED_METHODS=YES. This will log which method names have been overridden by categories, just in case that is the issue.
回答2:
It looks like you have two modules defining the same function, one in libSecurIDLib.a(mem.o) and pdcrypte2.o. These should be in their own namespaces (C++) or they should be prefixed so they don't collide (C).
There are work arounds if that's impossible, but it's better name things safely.
来源:https://stackoverflow.com/questions/6925609/how-to-include-static-libraries-which-have-same-names-for-object-files-within-th