Why can't clang with libc++ in c++0x mode link this boost::program_options example?
Solution 1:
You need to rebuild boost using clang++ -stdlib=libc++.
libc++ is not binary compatible with gcc's libstdc++ (except for some low level stuff such as operator new). For example the std::string
in gcc's libstdc++ is refcounted, whereas in libc++ it uses the "short string optimization". If you were to accidentally mix these two strings in the same program (and mistake them for the same data structure), you would inevitably get a run time crash.
This accident is exactly what has occurred in your case.
In order to turn this run time crash into a link time error, libc++ uses a C++11 language feature called inline namespace
to change the ABI of std::string
without impacting the API of std::string
. That is, to you std::string
looks the same. But to the linker, std::string
is being mangled as if it is in namespace std::__1
. Thus the linker knows that std::basic_string
and std::__1::basic_string
are two different data structures (the former coming from gcc's libstdc++ and the latter coming from libc++).