| | |
undefined reference to 'main'
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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:
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]
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!
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:
Oh, and when I start my computer, I use the power button, not a .o file :lol:
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
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!
The and the linker should take care of everything... I think... (been a li'l while...)
#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. C++ Syntax (Toggle Plain Text)
$ g++ myheader.cpp main.cpp
![]() |
Similar Threads
- compiling using g++ results to undefined reference (C++)
- undefined reference error -HELP! (C++)
- Dev C++ linker errors, undefined reference (C++)
- [Linker error] undefined reference to `CQTMovieFile::CQTMovieFile()' (C++)
- What is it meaned [Linker error] undefined reference to `MAPILogon@24' (C++)
- Dev-C++, GLUI linker error, undefined reference (C++)
- undefined reference errors when using C++ Sockets Library (C++)
Other Threads in the C++ Forum
- Previous Thread: Open a file to an array
- Next Thread: help: string and random number generator Questions
Views: 8289 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






