Xcode - 命令 /Developer/usr/bin/clang 失败,退出代码为 1
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7560239/
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
Xcode - Command /Developer/usr/bin/clang failed with exit code 1
提问by basir
I'm just starting programming, and trying to learn C.
我刚刚开始编程,并试图学习 C。
For my homework I had to design a program, and I'm pretty sure my code is right, but whenever I try to test it, or even try programs directly from the book, I get this error.
对于我的家庭作业,我必须设计一个程序,而且我很确定我的代码是正确的,但是每当我尝试测试它,甚至直接从书中尝试程序时,我都会收到此错误。
Ld "/Users/BasirJamil/Library/Developer/Xcode/DerivedData/Lab_2-fuyrgmtkjwgafzctwttcpwxptwox/Build/Products/Debug/Lab 2.app/Contents/MacOS/Lab 2" normal x86_64
cd "/Users/BasirJamil/Desktop/Lab 2"
setenv MACOSX_DEPLOYMENT_TARGET 10.7
/Developer/usr/bin/clang -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.7.sdk -L/Users/BasirJamil/Library/Developer/Xcode/DerivedData/Lab_2-fuyrgmtkjwgafzctwttcpwxptwox/Build/Products/Debug -F/Users/BasirJamil/Library/Developer/Xcode/DerivedData/Lab_2-fuyrgmtkjwgafzctwttcpwxptwox/Build/Products/Debug -filelist "/Users/BasirJamil/Library/Developer/Xcode/DerivedData/Lab_2-fuyrgmtkjwgafzctwttcpwxptwox/Build/Intermediates/Lab 2.build/Debug/Lab 2.build/Objects-normal/x86_64/Lab 2.LinkFileList" -mmacosx-version-min=10.7 -framework Cocoa -o "/Users/BasirJamil/Library/Developer/Xcode/DerivedData/Lab_2-fuyrgmtkjwgafzctwttcpwxptwox/Build/Products/Debug/Lab 2.app/Contents/MacOS/Lab 2"
ld: duplicate symbol _main in /Users/BasirJamil/Library/Developer/Xcode/DerivedData/Lab_2-fuyrgmtkjwgafzctwttcpwxptwox/Build/Intermediates/Lab 2.build/Debug/Lab 2.build/Objects-normal/x86_64/File.o and /Users/BasirJamil/Library/Developer/Xcode/DerivedData/Lab_2-fuyrgmtkjwgafzctwttcpwxptwox/Build/Intermediates/Lab 2.build/Debug/Lab 2.build/Objects-normal/x86_64/main.o for architecture x86_64
Command /Developer/usr/bin/clang failed with exit code 1
Can somebody please explain what the problem is, and how I can fix it, without getting overly technical (if possible)? Remember, I'm still new to programming
有人可以解释一下问题是什么,以及我如何解决它,而不会过于技术化(如果可能的话)?记住,我还是编程新手
Thanks In Advance
提前致谢
回答by Mark Granoff
ld: duplicate symbol _main in /Users/BasirJamil/Library/Developer/Xcode/DerivedData/Lab_2
You have a variable (most likely) or a function defined more than once. In fact, it may be that you have defined _main
twice.
您有一个变量(很可能)或一个函数定义了多次。事实上,可能是你定义了_main
两次。
It helps to read the whole error message, not just the last line. :-)
它有助于阅读整个错误消息,而不仅仅是最后一行。:-)
Check your code.
检查您的代码。
回答by Mark Granoff
You can also get this error of you include an implementation file rather than a header file accidentally. e.g. #import "MyClass.m" instead of #import "MyClass.h"
您也可能会在意外包含实现文件而不是头文件时出现此错误。例如 #import "MyClass.m" 而不是 #import "MyClass.h"
回答by garafajon
As stated in the other answers, this happens because the linker is finding more than one symbol that is named the same thing... in this case "_main". There are a number of reasons why this can happen (global variables/methods of same name, global variables/methods defined--as opposed to declared--in .h files included more than once, etc.)
正如其他答案中所述,发生这种情况是因为链接器找到了多个名称相同的符号......在这种情况下是“_main”。发生这种情况的原因有很多(同名的全局变量/方法、定义的全局变量/方法——与声明相反——在 .h 文件中包含不止一次等)
However, this being Xcode related, the first thing you might want to check is your build phases. It is possible for your "Compile Sources" build phase is compiling the same file more than once. In your case, it is probably "main.m".
但是,这是与 Xcode 相关的,您可能想要检查的第一件事是您的构建阶段。您的“编译源”构建阶段可能会多次编译同一个文件。在您的情况下,它可能是“main.m”。
Somehow this happened to me today after I added a lot of localized .xib files to my project and Xcode crashed.
在我向我的项目添加了很多本地化的 .xib 文件并且 Xcode 崩溃后,今天不知何故发生在我身上。
回答by edzio27
I had this error, what i do is just look in my "Build Phases" -> "Compile Sources" and delete all duplicate files.
我遇到了这个错误,我所做的只是查看我的“构建阶段”->“编译源”并删除所有重复文件。
回答by AlexZenadi
This error is talking about 2 functions with same name - main have been defined. Per your description that you are new to C, so I guess you might make the same stupid mistake as me. At the very beginning, I just simply drag all the sources files I can download to study the C, 2 projects included LUA and http-parser then I started to build and run my Xcode project then I encountered the exactly same error message you posted at here.
此错误涉及 2 个具有相同名称的函数 - main 已被定义。根据您的描述,您是 C 新手,所以我猜您可能会犯和我一样的愚蠢错误。一开始,我只是简单地拖动我可以下载的所有源文件来研究 C,2 个项目包括 LUA 和 http-parser 然后我开始构建和运行我的 Xcode 项目然后我遇到了与您发布的完全相同的错误消息这里。
回答by cecilia zhang
I got the same error, I used file-> open recent-> clear menu. after I have done it, the error disappear. There is nothing wrong with your code, just clean the history...
我遇到了同样的错误,我使用了文件 -> 打开最近 -> 清除菜单。完成后,错误消失。您的代码没有任何问题,只需清理历史记录...