Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ld: 1 duplicate symbol for architecture x86_64

Tags:

c

xcode6

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;
}

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)

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!

like image 647
Thomas Fearn Avatar asked Sep 19 '14 23:09

Thomas Fearn


People also ask

What does 1 duplicate symbol for architecture x86_64 mean?

Well, it means we're trying to link the same symbol name (in our case, a method) from two (or more) different source files. The fix was easy: rename one of the methods by updating the header file, the source file (. c or .

What is undefined symbols for architecture x86_64?

Why Is the Undefined Symbols for Architecture x86_64: Error Happening? This error is happening due to the lack of included values inside the declared statements in your code. The browser is going to render the information incorrectly and show this error, especially if you are working with Main and Similarity tools.

What does duplicate symbol mean in C++?

Duplicate symbols occur when you have both added an implementation file (. cpp) to your project and #included it. This way, the implementation file (. cpp) gets compiled twice: once as a module in your project (as it is added to your project) and subsequently as a piece of #included code.


1 Answers

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.

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.

like image 69
Crowman Avatar answered Oct 08 '22 20:10

Crowman