Home >Backend Development >C++ >Why does clang with libc in c 0x mode fail to link this boost::program_options example?
Compiling an example program involving boost::program_options with clang using libc and c 0x mode results in undefined symbol errors. However, the same code compiles and links successfully using g -mp-4.7 or clang without libc .
The issue arises from the incompatibility of boost::program_options, which is built using libstdc , with libc . In order to avoid accidental mixing of incompatible standard libraries and ensure binary compatibility, libc employs a C 11 feature called "inline namespace." This changes the Application Binary Interface (ABI) of std::string without affecting its Application Programming Interface (API).
To resolve this compatibility issue, rebuild boost using clang with the -stdlib=libc flag:
clang++ -stdlib=libc++
This action will rebuild boost with libc and avoid the symbol conflicts that arise from using incompatible standard libraries.
The above is the detailed content of Why does clang with libc in c 0x mode fail to link this boost::program_options example?. For more information, please follow other related articles on the PHP Chinese website!