Froskoy
Froskoy

Reputation: 3027

Can't decipher error from linker

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.

Upvotes: 0

Views: 617

Answers (2)

111111
111111

Reputation: 16158

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++

g++ new.cpp

Upvotes: 3

Daniel Fischer
Daniel Fischer

Reputation: 183918

int main();

declares a main, but doesn't define one. Try

int main() {}

instead, and it compiles (but with warnings about signed/unsigned comparisons) and links without problems when compiled with g++.

On line 37, did you intend

queue >>= bsize;

instead of

queue >> bsize;

?

Upvotes: 0

Related Questions