PDA

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


jinxjinx
June 27th, 2006, 10:10 PM
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 27th, 2006, 10:18 PM
yes dont use void main its bad practice use int main () {} also are there and log outputs for the failure?

Thirsteh
June 27th, 2006, 10:30 PM
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 27th, 2006, 10:37 PM
try using g++ instead of gcc ...

jinxjinx
June 27th, 2006, 11:55 PM
must have been a bug. worked after i reset eclipse.
thanks

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