Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kperryua

macrumors newbie
Original poster
Sep 1, 2005
2
0
I'm trying to compile a very simple C++ program on the command line using gcc. It successfully creates the object files and all that, but the linker spits these errors out at me:

Code:
/usr/bin/ld: Undefined symbols:
std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))
std::ios_base::Init::Init()
std::ios_base::Init::~Init()
std::cout
std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)
std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
___gxx_personality_v0
collect2: ld returned 1 exit status

This suggests to me that the linker for some reason can't find the C++ standard libraries. What's up with that? I swear it was working a week ago...

I installed Fink recently... might that have anything to do with it?

Anyone know a fix?
 

WebMongol

macrumors member
Sep 19, 2004
50
0
Bay Area, CA
ChrisBrightwell said:
g++ is just a symlink to gcc.

kperryua, can you build HelloWorld.cpp?

Even if g++ and gcc are sym links to the same program (actually it's not true for Mac OS X 10.3.9) they behave differently depending which name was used for invocation.
g++ by default calls linker (ld) and specify C++ std library(-lstdc++).

One can do this explicitly by building C++ program with extra parameter: -lstdc++. So to compile C++ hello.cc one can use
g++ hello.cc -o hello1
OR
gcc hello.cc -lstdc++ -o hello2
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.