Home >Backend Development >C++ >Why does clang with libc in c 0x mode fail to link this boost::program_options example?

Why does clang with libc in c 0x mode fail to link this boost::program_options example?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-03 13:43:30365browse

Why does clang with libc   in c  0x mode fail to link this boost::program_options example?

Why doesn't clang with libc in c 0x mode 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

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).

The Solution

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn