开发者

Xcode - Command /Developer/usr/bin/clang failed with exit code 1

I'm just starting programming, and trying to learn 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/Debu开发者_StackOverflowg/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


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.

It helps to read the whole error message, not just the last line. :-)

Check your code.


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"


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.)

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".

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


I had this error, what i do is just look in my "Build Phases" -> "Compile Sources" and delete all duplicate files.


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.


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜