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
谢谢提前
6 个解决方案
#1
11
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.
检查你的代码。
#2
5
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"
您还可以得到这个错误,包括一个实现文件,而不是意外的头文件。例如# MyClass进口”。而不是#import "MyClass.h"
#3
5
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崩溃之后,今天我遇到了这种情况。
#4
1
I had this error, what i do is just look in my "Build Phases" -> "Compile Sources" and delete all duplicate files.
我有这个错误,我所做的只是查看我的“构建阶段”——>“编译源”并删除所有重复的文件。
#5
1
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.
这个错误讨论的是两个具有相同名称的函数——main已经被定义。根据你对C的描述,我想你可能会犯和我一样愚蠢的错误。在开始的时候,我只是简单地拖拽我可以下载的所有源文件来研究C, 2个项目包括LUA和http解析器,然后我开始构建和运行我的Xcode项目,然后我遇到了你在这里发布的完全相同的错误信息。
#6
0
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...
我得到了相同的错误,我使用了文件->打开了最近的>清楚的菜单。在我完成之后,错误就消失了。你的代码没有问题,只是清理历史……
#1
11
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.
检查你的代码。
#2
5
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"
您还可以得到这个错误,包括一个实现文件,而不是意外的头文件。例如# MyClass进口”。而不是#import "MyClass.h"
#3
5
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崩溃之后,今天我遇到了这种情况。
#4
1
I had this error, what i do is just look in my "Build Phases" -> "Compile Sources" and delete all duplicate files.
我有这个错误,我所做的只是查看我的“构建阶段”——>“编译源”并删除所有重复的文件。
#5
1
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.
这个错误讨论的是两个具有相同名称的函数——main已经被定义。根据你对C的描述,我想你可能会犯和我一样愚蠢的错误。在开始的时候,我只是简单地拖拽我可以下载的所有源文件来研究C, 2个项目包括LUA和http解析器,然后我开始构建和运行我的Xcode项目,然后我遇到了你在这里发布的完全相同的错误信息。
#6
0
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...
我得到了相同的错误,我使用了文件->打开了最近的>清楚的菜单。在我完成之后,错误就消失了。你的代码没有问题,只是清理历史……