开发者

Xcode beginner needs help starting debugging

开发者 https://www.devze.com 2023-01-30 09:32 出处:网络
I\'m a novice C++ programmer and I only know how to program in visual studio, but my PC crashed and I only have mac Xcode available.

I'm a novice C++ programmer and I only know how to program in visual studio, but my PC crashed and I only have mac Xcode available.

I wrote a .cpp like in visual studio, but when I had it build, it gave me this error..

ld: duplicate symbol _main in /Users/karen/Desktop/BD/build/BD.build/Debug/BD.build/Objects-normal/x86_64/bd1.o and /Users/karen/Desktop/BD/build/BD.build/Debug/BD.build/Objects-n开发者_开发百科ormal/x86_64/main.o

Anyone know what to do?


This error is telling you that you have defined "main" in two separate files: (probably "bd1.cpp" and "main.cpp"). If you didn't create the file "main.cpp" (or "main.cc"); it's possible that XCode created a sample "main" for you when you set up the project.

A program can have only one function named "main", so you need to get rid of one of them...


Its a linker error, so you can't really "debug" this. Can we see some code? bd1 and main have a duplicate symbol - so u use maybe same variable/function names without namespaces? Its also possible, that you need to "cleanup" before you try to build (old symbols in object files) - but its like guessing without seeing your code...


Either bd1.cpp or main.cpp should go, as they both have a main function. There can only be one main function in a C/C++ program. Most likely main.cpp was automatically created for you when you created a new Xcode project for existing codebase. So search for main.cpp/main.c in your project and remove it.

0

精彩评论

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

关注公众号