Thursday, April 07, 2005
Undefined Symbol
I was trying to compile a C++ program:
gcc a.cpp
Got this:
Undefined first referenced
symbol in file
cerr /var/tmp/ccKpgRuk.o
cout /var/tmp/ccKpgRuk.o
string_char_traits::move(char *, char const *, unsigned int)/var/tmp/ccKpgRuk.o
endl(ostream &) /var/tmp/ccKpgRuk.o
__out_of_range(char const *) /var/tmp/ccKpgRuk.o
ostream::operator<<(ostream &(*)(ostream &))/var/tmp/ccKpgRuk.o
ostream::write(char const *, int) /var/tmp/ccKpgRuk.o
string_char_traits::length(char const *)/var/tmp/ccKpgRuk.o
__length_error(char const *) /var/tmp/ccKpgRuk.o
string_char_traits::copy(char *, char const *, unsigned int)/var/tmp/ccKpgRuk.o
ostream::operator<<(char const *) /var/tmp/ccKpgRuk.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
This is caused by not linking to the C++ library,
gcc -lstdc++ a.cpp
would fix it.
gcc a.cpp
Got this:
Undefined first referenced
symbol in file
cerr /var/tmp/ccKpgRuk.o
cout /var/tmp/ccKpgRuk.o
string_char_traits
endl(ostream &) /var/tmp/ccKpgRuk.o
__out_of_range(char const *) /var/tmp/ccKpgRuk.o
ostream::operator<<(ostream &(*)(ostream &))/var/tmp/ccKpgRuk.o
ostream::write(char const *, int) /var/tmp/ccKpgRuk.o
string_char_traits
__length_error(char const *) /var/tmp/ccKpgRuk.o
string_char_traits
ostream::operator<<(char const *) /var/tmp/ccKpgRuk.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
This is caused by not linking to the C++ library,
gcc -lstdc++ a.cpp
would fix it.
Comments:
<< Home
Even if the libstdc++.so is in /usr/local/lib directory, I got an error when I did:
gcc -L /usr/local/lib -lstdc++ test1.cpp
It turned out that I had to do:
gcc -lstdc++ test1.cpp
to get it work.
Post a Comment
gcc -L /usr/local/lib -lstdc++ test1.cpp
It turned out that I had to do:
gcc -lstdc++ test1.cpp
to get it work.
<< Home
