Xcode 中的重复符号错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14367793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Duplicate symbol error in Xcode
提问by user591410
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..
添加自己的框架后尝试构建项目时,我在 Xcode 4.5.1 中遇到“重复符号”错误。我验证了重复的框架文件,但没有。但是当我将框架添加到项目时,它会抱怨这些错误。请建议..
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..
提前致谢..
采纳答案by kuuldor
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.
这些符号在 crt.o 中,标准 C 库的启动代码。通常它应该是可执行文件的入口点来初始化全局变量和对象。它还会调用您的主函数。
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.
但是对于框架,你不应该将它包含在你的二进制文件中,因为框架不应该有 main。我相信您在框架的目标构建设置中将“与标准库链接”选项设置为“是”。这会将 crt.o 链接到您的框架中。并且当你将框架链接到一个项目中时,会出现重复的符号。
Please set the option "Link with Standard Library" to NO in your build setting.
请在您的构建设置中将选项“与标准库链接”设置为否。
回答by farhad hossain
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.
我在使用两个第三方框架时遇到了同样的问题。我通过从构建设置中的“其他链接器标志”中删除“all_load”解决了这个问题。
回答by Developer
Your application has provided an implementation in which there are 8 duplication symbols.
您的应用程序提供了一个实现,其中有 8 个重复符号。
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.)
您正在导入文件 .m 和 .h 中的任何头文件:-(从一处删除。)
You are importing any .m file somewhere. :- (Import .h file instead of .m file)
您正在某处导入任何 .m 文件。:- (导入 .h 文件而不是 .m 文件)
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.)
您已经在任何 .h 文件中的 @interface{} 外部(上方)中定义并声明了任何 const 变量,它可能会被复制。:- (在 .m 文件中做。)
回答by Vinod Supnekar
Also check, if global variables like constants are defined correctly in .h
file in application.
还要检查是否.h
在应用程序的文件中正确定义了诸如常量之类的全局变量。
The correct way of defining global variable is to use extern
variable in .h
file.
定义全局变量的正确方法是extern
在.h
文件中使用变量。
Note :This is not an issue with the previous Xcode version. I faced the problem with Xcode 6.3 and it was solved.
注意:这不是以前的 Xcode 版本的问题。我在 Xcode 6.3 上遇到了这个问题,并且解决了。
回答by Edoardo
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 SETTINGSbefore doing this (especially those related to simulator devices).
Xcode 将在第一次构建和运行后恢复它。 请确保在执行此操作之前备份所有设置(尤其是与模拟器设备相关的设置)。
Tested on Xcode Version 7.2.1 (7C1002)
在 Xcode 版本 7.2.1 (7C1002) 上测试