undefined reference to 'main'

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Sep 2006
Posts: 236
Reputation: FireSBurnsmuP is an unknown quantity at this point 
Solved Threads: 1
FireSBurnsmuP's Avatar
FireSBurnsmuP FireSBurnsmuP is offline Offline
Posting Whiz in Training

undefined reference to 'main'

 
0
  #1
Dec 4th, 2006
Alright, people. I am writing a simple, command based program simulatin minesweeper, using a txt file for the map. I am getting characters and stuff in from the file, and converting them to integers to determine the size of the map.

Now all this is going alright, but I am getting a problem involving crt1.o, which i used to start up my computer. I am getting the compiler error: undefined reference to 'main'

I understand that this is a problem relating to the fact that my .cpp file doesn't have a main function.

I could just put one in, but the problem is that this is an implementation file for a header, not a main file. This file isn't supposed to have a main function in it. How should I fix this?

/*This is on my debian 'etch' system, I am using gedit to edit the files and g++ to compile them. my gcc is version 4.1.2. */

[EDIT] I suppose I could just keep writing it, because if that is the only error I get it'll still compile in visual c++ for windoze, and that's what my instructor will be using... [/EDIT]
Last edited by FireSBurnsmuP; Dec 4th, 2006 at 10:29 pm.
Damn computer! It ate everything!
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,580
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: undefined reference to 'main'

 
0
  #2
Dec 4th, 2006
When you run a program, the program starts with the main() function by definition. You need a main() somewhere in your project, and whatever file contains main() should be the one you compile to create your executable. You can just put main in another file (e.g. main.cpp) and that way keep your implementation stuff separate.

Oh, and when I start my computer, I use the power button, not a .o file :lol:
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 236
Reputation: FireSBurnsmuP is an unknown quantity at this point 
Solved Threads: 1
FireSBurnsmuP's Avatar
FireSBurnsmuP FireSBurnsmuP is offline Offline
Posting Whiz in Training

Re: undefined reference to 'main'

 
0
  #3
Dec 4th, 2006
XD lol yeah I know, I don't personally use that file...

and I know, but I am making this implementation file myself, so don't I have to compile that too, in order for the program using the header to be able to? or will g++ figure it out with the line #include "myheader.h"? The director of the whole cse thing told me to do it this way...
Damn computer! It ate everything!
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,580
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: undefined reference to 'main'

 
1
  #4
Dec 4th, 2006
The #include "myheader.h" will essentially paste the contents of myheader.h into the top of whatever file it is #included into. So it'll be comiled just fine. In order to get the .cpp file compiled, you can just specify it first on the command line, e.g.
  1. $ g++ myheader.cpp main.cpp
and the linker should take care of everything... I think... (been a li'l while...)
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 236
Reputation: FireSBurnsmuP is an unknown quantity at this point 
Solved Threads: 1
FireSBurnsmuP's Avatar
FireSBurnsmuP FireSBurnsmuP is offline Offline
Posting Whiz in Training

Re: undefined reference to 'main'

 
0
  #5
Dec 4th, 2006
thanks a lot! I do believe "I owe you one, BPS." You may have saved my life.

( and bravo on the BPS avi, I'm a pretty big fan.)
Damn computer! It ate everything!
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,580
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: undefined reference to 'main'

 
0
  #6
Dec 4th, 2006
Haha, anyone who can recognize BPS deserves a hand... and your ava isn't bad either
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 8289 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC