The -stdlib=libstdc flag directs the compiler and linker to use the libstdc standard library implementation during compilation. However, it's not always necessary to explicitly specify this flag.
When Using Linux or Modern GCC on Other Platforms
For most Linux distributions and current GCC versions, libstdc is the default standard library implementation. Therefore, using the -stdlib=libstdc flag is not required when compiling C 11 code on these platforms. Simply use the following commands:
g++ -std=c++11 input.cxx -o a.out (GNU compiler) g++ -std=gnu++11 input.cxx -o a.out
On macOS Prior to Mavericks
On macOS releases before Mavericks, g was a symbolic link to clang . Apple's older libstdc implementation was the default. To use libc , which provides C 11 library support, the -stdlib=libc flag was necessary:
g++ -std=c++11 -stdlib=libc++ input.cxx -o a.out (clang, not GNU compiler!) g++ -std=gnu++11 -stdlib=libc++ input.cxx -o a.out (clang, not GNU compiler!) clang++ -std=c++11 -stdlib=libc++ input.cxx -o a.out clang++ -std=gnu++11 -stdlib=libc++ input.cxx -o a.out
On macOS Since Mavericks
On macOS Mavericks and later, libc is the default. Explicitly passing the -stdlib=libstdc flag is unnecessary:
clang++ -std=c++11 input.cxx -o a.out clang++ -std=gnu++11 input.cxx -o a.out
Exceptions
There may be specific cases where explicitly using the -stdlib=libstdc flag is beneficial:
The above is the detailed content of When is the -stdlib=libstdc Flag Required During Compilation?. For more information, please follow other related articles on the PHP Chinese website!