LD:适用于建筑x86_64的1个重复的符号 [英] ld: 1 duplicate symbol for architecture x86_64
问题描述
我非常非常新的C和C ++编程,并在软件编程经验非常少(在基于Web的我的背景),但我想用C / C ++和X code实验...所以,我发现这个code(和网上很多类似的变异):
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):
#include <stdio.h>
int main()
{
printf ("Test");
return 0;
}
然而,当我来到编译它在X $ C $三我收到以下错误:
Yet when I come to compile it in Xcode I get the following error:
> 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)
也许X code是错误的事情对我来说,使用作为一个新手?如果任何人都可以推荐一个更好的编译器,这将是巨大的!
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!
推荐答案
当您创建X code上新建一个项目,它会自动给你一个启动文件,的main()
在里面。如果创建一个新的文件,如 first.c
,然后粘贴您的测试code到它,你会被定义主()
两次,并获得该错误。
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.
您需要删除的文件(如的main.c
或 main.m文件
),其中X code提供了新项目,或者剪切和样品code粘贴到该文件,而不是创建一个新的。
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.
这篇关于LD:适用于建筑x86_64的1个重复的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!