Friday, June 26, 2009

Leopard and gcc

Starting from the very beginning with C++, here is that famous chestnut (filename is test.cpp):


int main () {
std::cout << "Hello, world!";
std::cout << std::endl;
return 0;
}


And immediately I'm scratching my head at weirdness on the command line in Leopard. There is a difference between gcc and g++. Why? It seems the linker is having trouble finding libstdc++. Now I have to remember to use g++.

$ g++ -o test test.cpp
$ ./test
Hello, world!
$ gcc -o test test.cpp
Undefined symbols:
...
...
"std::cout", referenced from:
__ZSt4cout$non_lazy_ptr in ccJ7ynTQ.o
ld: symbol(s) not found
collect2: ld returned 1 exit status


Department of "WTF".