I have the following code:
#include <iostream> using namespace std; class testing{ int test() const; int test1(const testing& test2); }; int testing::test() const{ return 1; } int testing::test1(const testing& test2){ test2.test(); return 1; }
after compilation, it gives me the following error:
Undefined symbols: '_main', referenced from: start in crt1.10.5.o ld: symbol(s) not found collect2: ld returned 1 exit status
Why is it complaining about main? Can’t i declare main in another file and include this one?
Thanks a lot!
You have tried to link it already:
That will not only compile it, but try to already create the executable. The linker then is unable to find the main function that it needs. Well, do it like this:
That will create two files file.o and hasmain.o, both only compiled so far. Now you can link them together with g++:
It will automatically figure out that those are files already compiled, and invoke the linker on them to create a file ‘my_program’ which is your executable.