I'm sorry, lately I've been managing to hit "Send" by accident all two often...
#include <string>
#include <iostream>
int main(int argc, char* argv[])
{
(void)argc;
(void)argv;
std::string s("foo");
std::cout << s << std::endl;
return 0;
}
$ c++ -c test.cc
$ c++ -o test test.o
that works.
$ cc -o test test.o
that doesn't (fails with a message similar to Petar's).
$ cc -o test test.o -lstdc++
that works (gcc 4.7; Linux)
$ cc -static -o test test.o -lstdc++
that works.
$ cc -static -o test -lstdc++ test.o
that fails.
And:
$ c++ -static -o test test.o
that works.
By using c++ as the frontend, it just happens to add -lstdc++ (among
other things) in the right location, where the linker can actually see
the needed symbols before processing the objects (or archives) that
contain the definitions. With shared objects GCC behaves differently
in terms of symbol resolution, and that's why order doesn't seem to
matter. For other compilers order still matters, even in that case.
I'm not familiar with the OS X toolchain to be able to telll you why
the case you mentioned fails there (from the few times I've dealt with
it, I remember it's not a happy place).
I hope this helps,
Marcelo