Error from Xcode making no sense to me????

Joined
Dec 21, 2009
Messages
1
Reaction score
0
Points
1
I wanna study the C++ in XCode. After installing, I just inputted a following sample code,

#include <iostream>
using namespace std;

int main()
{
int iterations = 0;
bool continue_loop = true;
while ( continue_loop != false )
{
iterations++;
cout << "the while loop has executed "
<< iterations << " times\n";
if ( iterations == 5 )
continue_loop = false;
}
return 0;
}

but the XCode said "it is fail", the reason is
"duplicate symbol _main in /Users/roger/Documents/Try/build/Try.build/Debug/Try.build/Objects-normal/x86_64/Try.o and /Users/roger/Documents/Try/build/Try.build/Debug/Try.build/Objects-normal/x86_64/main.o"

so please help me, is it my mistake to install the xcode or open a wrong file, or some reasons.

Thank you very much..........
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,770
Reaction score
2,110
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
The error code actually makes perfect sense, you have 2 "main" functions which isn't allowed. Every program you create can only have one main function, because that's the function that is run FIRST when the application is run. Looks like you have possibly two files called "Try.cpp" and "main.cpp"??

How did you create the XCode project for your test?

Regards
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top