Duplicate symbol error in Xcode

2019-03-27 00:32发布

问题:

I am encountering 'duplicate symbol' errors in Xcode 4.5.1 when I try to build a project after adding my own framework. I verified the framework files for duplicates and there are none. But when I add the framework to a project, it complains with these error. Please suggest..

duplicate symbol _NXArgc in:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib/crt1.3.1.o
/Users/idcc/Test/MyFW/Products/MyTestFW.framework/MyTestFW

duplicate symbol _NXArgv in:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib/crt1.3.1.o
/Users/idcc/Test/MyFW/Products/MyTestFW.framework/MyTestFW

duplicate symbol ___progname in:
  /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib/crt1.3.1.o
/Users/idcc/Test/MyFW/Products/MyTestFW.framework/MyTestFW

duplicate symbol _environ in:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib/crt1.3.1.o
/Users/idcc/Test/MyFW/Products/MyTestFW.framework/MyTestFW

duplicate symbol start in:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib/crt1.3.1.o
/Users/idcc/Test/MyFW/Products/MyTestFW.framework/MyTestFW
ld: 8 duplicate symbols for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Thanks in advance..

回答1:

Those symbols are in crt.o, the startup code of standard C library. Normally it should be the entry point of executable file to initialize global variables and objects. It will also call your main function.

But for a framework, you should not include it in your binary because framework should not have main. I believe you have "Link with Standard Library" option as "YES" in your framework's target build setting. This will link crt.o into your framework. And when you link the framework into a project, there will be duplicated symbols.

Please set the option "Link with Standard Library" to NO in your build setting.



回答2:

I had the same issue with using two third party framework. I resolved that by removing "all_load" from "Other Linker Flags" in build settings.



回答3:

Your application has provided an implementation in which there are 8 duplication symbols.

There are a number of ways you might have done this:

You have two modules declaring the same class. Perhaps one is no longer needed?

You are importing any header file in both the files .m and .h :-( Remove from one place.)

You are importing any .m file somewhere. :- (Import .h file instead of .m file)

You have defined and declared any const variable in outside(above) the @interface{} in any of .h file, it might being duplicated. :- (Do it in the .m file.)



回答4:

Also check, if global variables like constants are defined correctly in .h file in application.

The correct way of defining global variable is to use extern variable in .h file.

Note :This is not an issue with the previous Xcode version. I faced the problem with Xcode 6.3 and it was solved.



回答5:

If you have this problem only when you run the app in the simulator, it gets solved by deleting the local folder

~/Library/Developer/CoreSimulator

Xcode will restore it after the first build and run. PLEASE MAKE SURE YOU BACKUP ANY SETTINGS before doing this (especially those related to simulator devices).

Tested on Xcode Version 7.2.1 (7C1002)