I ran into this while trying to get an answer. But it looks like the poster had several files and they were not linked, and therefore an error.
But why am I getting this error when using a single file?
g++ myClass.cpp
/usr/lib/gcc/i686-redhat-linux/4.6.3/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
And why is mainit necessary here at compile time ( where will he find a mention of the main thing in my code )? mainis the starting point for code execution, but why does the compiler assume what I need mainhere. Can I define it in some other file and use it gcc -oto create an executable?
Or maybe I will miss something else in the code causing the error?
#include<iostream>
class myClass
{
public:
myClass()
{
std::cout<<"Constructor";
}
~myClass()
{
std::cout<<"Destructor";
}
};
source
share