Xcode - command / developer / usr / bin / clang failed with exit code 1

I am just starting to program and trying to learn C.

For my homework, I had to compile a program, and I am sure that my code is right, but whenever I try to test it or even try to run programs directly from a 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 someone please explain what the problem is, and how can I fix it without getting too technical (if possible)? Remember that I'm still new to programming

Thanks in advance

+4
source share
6 answers
 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. Actually, you may have defined _main twice.

This helps to read the entire error message, not just the last line. :-)

Check your code.

+11
source

You may also get this error if you accidentally included an implementation file rather than a header file. for example #import "MyClass.m" instead of #import "MyClass.h"

+5
source

As indicated in other answers, this is because the linker finds more than one character, which is called the same ... in this case "_main". There are a number of reasons why this can happen (global variables / methods with the same name, global variables / methods defined - unlike declared - .. h files included more than once, etc.).

However, this is due to Xcode, the first thing you can check is your build phases. It is possible that the โ€œCompile Sourcesโ€ build phase is the same file more than once. In your case, this is probably "main.m".

Somehow this happened to me today after I added a lot of localized .xib files to my project and Xcode crashed.

+5
source

I had this error, what am I doing, just look in "Build Phases" โ†’ "Compile Sources" and delete all duplicate files.

+1
source

This error speaks of 2 functions with the same name - main were defined. According to your description that you are new to C, I think you can make the same stupid mistake as me. At the very beginning, I just dragged all the source files that I can download to study C, 2 projects, including LUA and http-parser, after which I started creating and running an Xcode project, then I came across the same error message that you sent on here.

+1
source

I got the same error, I used the menu file-> open recent-> clear. after i did this, the error will disappear. There is nothing wrong with the code, just clear the story ...

0
source

All Articles