Jump to content

View more

Image of the Day

雑魚は多めにして、爽快感重視にしつつ・・・(´・ω・`)
早いとこ、ベースを作って、完成にもっていかないとね。
タイトルもまだ迷ってるだよなぁ。 
#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Beginner C++ Programming - Please Help with Errors

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 Art n Peace   Members   

148
Like
0Likes
Like

Posted 18 February 2012 - 12:19 PM

I'm using an old book that teaches programming and I keep getting an error that I don't understand. The book is:

Beginning C++ Game Programming by Michael Dawson

I've tried running the code in Dev-C++ and Netbeans IDE. No luck. I'm wondering if the lesson code within is dated (the book is old, 2004)? Here's the program I'm trying to run:

#include <iostream>
using namespace std;
/*
*
*/
int main()
{
	cout << "Game Over!" << endl;
	return 0;
}

Here's the error I'm getting:

build/Debug/Cygwin-Windows/main.o: In function `main':
/cygdrive/c/Users/User2/Documents/NetBeansProjects/cppLessons/main.cpp:15: multiple definition of `_main'
build/Debug/Cygwin-Windows/gameover2.o:/cygdrive/c/Users/User2/Documents/NetBeansProjects/cppLessons/gameover2.cpp:16: first defined here
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/Cygwin-Windows/cpplessons.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 3s)


What does this mean and how do I fix it? Thank you for your help.
I am in my art.

#2 CarbonAtom   Members   

100
Like
0Likes
Like

Posted 18 February 2012 - 12:35 PM

I tried running it in Code::Blocks and it worked fine.
The code looks fine to me.

#3 Art n Peace   Members   

148
Like
0Likes
Like

Posted 18 February 2012 - 12:47 PM

I think I figured it out, though I still don't understand what exactly happened.

There was a file which the IDE made by default called main.cpp. Based on the reading of the error which referenced that file, it was somehow being included in the compile process of the gameover.cpp. I don't know why. I deleted the main.cpp and the code ran perfectly.

It would be nice to understand what that error means though. Thanks.
I am in my art.

#4 mrjones   Members   

612
Like
0Likes
Like

Posted 18 February 2012 - 12:56 PM

This error means that you have defined more than one function called main in your code. When your IDE generated the main.cpp, it automatically generated a second main function that you yourself didn't write. Since both main.cpp and gameover2.cpp contained main function, the compiler couldn't decide which is the correct one and generated this error.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.