问题
I have an issue with a project that includes another project. The second project is an SDK which is required for the main project. At the moment, I have the SDK included in the main project as a static library. Both the SDK and the main project include the FBConnect and Unofficial Twitter SDK frameworks. I believe my problems are a result of these frameworks being included in both projects, but I have been unable to find a way to have them coexist without errors.
When the project builds for debug, it will not build for archive, and vice versa. I am able to resolve the issues each time by performing the same steps, but I would like to find a way to resolve it with no steps required between debug and archive builds.
When the project builds for debug without any errors, I get the following when trying an archive build:
Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_SBJSON", referenced from:
objc-class-ref in FBRequest.o
objc-class-ref in libSDK.a(ApiTvDiscussView.o)
objc-class-ref in libSDK.a(ApiWebView.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I then add the implementation files for the SBJSON library used by the FBConnect framework into the Compile Sources in Build Phases of the target, as per the linked screenshot: Screenshot
This then produces a different issue, as below:
duplicate symbol _OBJC_METACLASS_$_OAHMAC_SHA1SignatureProvider in:
/Users/Alan/Library/Developer/Xcode/DerivedData/App-gpvfsbaxxbvhsddtcbgkggquyltl/Build/Intermediates/ArchiveIntermediates/App/IntermediateBuildFilesPath/App.build/Release-iphoneos/App.build/Objects-normal/armv7/OAHMAC_SHA1SignatureProvider.o
./libSDK.a(OAHMAC_SHA1SignatureProvider.o)
.
.
.
.
.
duplicate symbol _OBJC_CLASS_$_TwitterDialog in:
/Users/Alan/Library/Developer/Xcode/DerivedData/App-gpvfsbaxxbvhsddtcbgkggquyltl/Build/Intermediates/ArchiveIntermediates/App/IntermediateBuildFilesPath/App.build/Release-iphoneos/App.build/Objects-normal/armv7/TwitterDialog.o
./libSDK.a(TwitterDialog.o)
duplicate symbol _OBJC_METACLASS_$_TwitterDialog in:
/Users/Alan/Library/Developer/Xcode/DerivedData/App-gpvfsbaxxbvhsddtcbgkggquyltl/Build/Intermediates/ArchiveIntermediates/App/IntermediateBuildFilesPath/App.build/Release-iphoneos/App.build/Objects-normal/armv7/TwitterDialog.o
./libSDK.a(TwitterDialog.o)
ld: 43 duplicate symbols for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Removing the implementation files for the OAUTH library used by the Unofficial Twitter SDK framework from the Compile Sources in Build Phases of the target removes these errors and the project archive build is successful.
When I attempt to build the project for debug, I get the opposite of these errors, firstly the OAUTH library symbols are undefined. Adding them to compile sources resolves the issue, then the SBJSON symbols are duplicated. Removing them from compile sources allows the debug build to complete successfully.
Does anyone know of a way to have these coexist in harmony so that I can do both debug and archive builds of the project without this file juggling every time?
回答1:
Both the Twitter and Facebook libraries are linking against the same SBJSON framework. Build both of them from code instead of using the static library. While doing this, remove the SBJSON reference from one of the SDK.
This is another reason why I hate building against static libraries. The problem will be un-solveable if you don't have the source code and the library maker didn't prefix his classes/methods.
Alternatively, you can use the newly released Facebook SDK, version 3.1, where they finally prefixed SBJSON to FBSBJSON.
来源:https://stackoverflow.com/questions/12611410/undefined-symbols-and-duplicate-symbols-errors-can-build-for-debug-or-release