-->

Duplicate Symbol XCode duplicate library for same

2020-07-13 07:34发布

问题:

Do you have any idea? Why XCode compilation give this result?

ld: duplicate symbol _kJSONDeserializerErrorDomain in 
  /Users/Shared/_BUILDS_/Debug-iphoneos/libLACDLibrary.a(CJSONDeserializer.o) 
  and /Users/Shared/_BUILDS_/Debug-iphoneos/libLACDLibrary.a(CJSONDeserializer.o)

回答1:

Hey, you probably have a duplicate reference in XCode to CJSONDeserializer, so it's compiled and linked twice.



回答2:

I have exactly the same problem. And it only complains for arm6 build (not arm7 build). I found a workaround: remove "-all_load" in Other linker flag under Build<-Get Info<-Target. I am not sure whether it is a correct workaround. I hope somebody can explain further and provide the correct workaround if this one is not.



回答3:

This error occurs if you link the same library into your project multiple times.

Project dependencies are subtly different from linking the libraries together. It is okay to have several projects depend on the same shared library project X; however, make sure that only one of the projects actually links the library.



回答4:

I hit this issue with code like the following in a file called Common.h:

void dumpViews(UIView* view, NSString *text, NSString *indent) {
  // ...
}

By adding static in front of the method definition it cleared the problem up for me:

static void dumpViews(UIView* view, NSString *text, NSString *indent) {
  // ...
}