My code is here and is in a file called new.cpp
I get the following error at the console:
[usr@host dir]$ gcc new.cpp
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
/tmp/ccVKDKZm.o: In function `__static_initialization_and_destruction_0(int, int)':
new.cpp:(.text+0x23): undefined reference to `std::ios_base::Init::Init()'
new.cpp:(.text+0x32): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
I have no idea how to debug this – any ideas?
Many thanks.
The error you have is a link error, your code compiled fine. The error is telling you it is unable to link to some standard library elements.
The reason you have got this is because you are compiler C++ with the gcc C frontend, well actually gcc will compile it as C++ but then will not link it against the C++ std lib.
The solution is simple, use the c++ front end, g++