PDA

View Full Version : undefined reference to `main' in eclipse



jinxjinx
June 28th, 2006, 03:10 AM
im using the c++ plug in for eclipse and im tyring to compile and run my hello world program and i get this:


**** Full rebuild of configuration Debug for project test ****

make -k clean all
rm -rf ./testmain.d ./testmain.o test

Building file: ../testmain.cpp
Invoking: GCC C++ Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -otestmain.o ../testmain.cpp
Finished building: ../testmain.cpp

Building target: test
Invoking: GCC C++ Linker
gcc -otest ./testmain.o
/usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../lib/crt1.o: In function `_start':../sysdeps/i386/elf/start.S:115: undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [test] Error 1
make: Target `all' not remade because of errors.
Build complete for project test


my hello world program is here:

#include <iostream>
using namespace std;
void main()
{
cout << "Hello World";
}

any help would be great thanks!

Stromham
June 28th, 2006, 03:18 AM
yes dont use void main its bad practice use int main () {} also are there and log outputs for the failure?

Thirsteh
June 28th, 2006, 03:30 AM
I don't have the ability to test this out thoroughly at the moment, I do have one suggestion however;

Change the main void to an int :)

#include <iostream>
using namespace std;
int main()
{
cout << "Hello World";
}

This should work. If it doesn't, 'gcc -otest' doesn't work with C++ perhaps?

scxtt
June 28th, 2006, 03:37 AM
try using g++ instead of gcc ...

jinxjinx
June 28th, 2006, 04:55 AM
must have been a bug. worked after i reset eclipse.
thanks

Rinnan
November 6th, 2008, 09:33 PM
Yes, I had this same problem, and this same solution worked.

psa3ebres
June 7th, 2012, 11:41 AM
What i have noticed is that whenever i create a new Project and a source file, I have to save the source file before I build, otherwise i get the undefined reference to 'main' error. Hope this help.