C语言 ld:架构 x86_64 的 1 个重复符号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25943779/
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
ld: 1 duplicate symbol for architecture x86_64
提问by Thomas Fearn
I'm very very new to C and C++ programming, and have very little experience in Software Programming (my background is Web Based) But I'm trying to experiment with C / C++ and Xcode... So I've found this code (and many similar variations online):
我对 C 和 C++ 编程非常陌生,并且在软件编程方面的经验很少(我的背景是基于 Web 的)但是我正在尝试使用 C/C++ 和 Xcode ......所以我找到了这段代码(以及许多类似的在线变体):
#include <stdio.h>
int main()
{
printf ("Test");
return 0;
}
Yet when I come to compile it in Xcode I get the following error:
然而,当我在 Xcode 中编译它时,我收到以下错误:
> duplicate symbol _main in:
> /Users/thomas/Library/Developer/Xcode/DerivedData/test-etqojvxbxhxjqeggdzkbfufvbeza/Build/Intermediates/test.build/Debug/test.build/Objects-normal/x86_64/first.o
> /Users/thomas/Library/Developer/Xcode/DerivedData/test-etqojvxbxhxjqeggdzkbfufvbeza/Build/Intermediates/test.build/Debug/test.build/Objects-normal/x86_64/main.o
> ld: 1 duplicate symbol for architecture x86_64 clang: error: linker
> command failed with exit code 1 (use -v to see invocation)
Maybe Xcode is the wrong thing for me to be using as a newbie? If anyone could recommend a better compiler, that would be great too!
也许Xcode对我来说是一个错误的新手?如果有人能推荐一个更好的编译器,那也太棒了!
采纳答案by Crowman
When you create a new project in Xcode, it automatically gives you a starting file with main()in it. If you created a new file, such as first.c, and then pasted your test code into it, you'll be defining main()twice, and getting that error.
当您在 Xcode 中创建一个新项目时,它会自动为您提供一个起始文件main()。如果您创建了一个新文件,例如first.c,然后将您的测试代码粘贴到其中,您将定义main()两次,并得到该错误。
You need to either delete the file (such as main.c, or main.m) that Xcode provides in your new project, or cut and paste your sample code into that file, instead of creating a new one.
您需要删除Xcode 在新项目中提供的文件(例如main.c、 或main.m),或者将示例代码剪切并粘贴到该文件中,而不是创建一个新文件。

