Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate symbol error in Xcode

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..

like image 608
user591410 Avatar asked Jan 16 '13 21:01

user591410


4 Answers

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.

like image 169
farhad hossain Avatar answered Sep 17 '22 13:09

farhad hossain


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.

like image 25
kuuldor Avatar answered Sep 18 '22 13:09

kuuldor


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.)

like image 33
Developer Avatar answered Sep 18 '22 13:09

Developer


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.

like image 24
Vinod Supnekar Avatar answered Sep 18 '22 13:09

Vinod Supnekar