Home >Backend Development >C++ >When is the \'-stdlib=libstdc \' Flag Required When Compiling with GCC?

When is the \'-stdlib=libstdc \' Flag Required When Compiling with GCC?

Linda Hamilton
Linda HamiltonOriginal
2024-10-24 01:27:29220browse

When is the

When to Use the "-stdlib=libstdc " Flag When Compiling with GCC

In some scenarios, explicitly setting the "-stdlib=libstdc " flag is necessary when compiling with GCC. Here are the circumstances:

On Linux:

By default, Linux distributions use libstdc as the standard C library. Moreover, modern versions of GCC inherently support C 11 in their bundled libstdc . Therefore, to compile C 11 code on Linux, simply using the "-std=c 11" flag with g should suffice:

g++ -std=c++11 input.cxx -o a.out

On Pre-Mavericks OS X:

Historically, g on OS X was an alias for clang . In this context, Apple's older version of libstdc was the default. To leverage libc , which included C 11 support, you had to explicitly specify "-stdlib=libc ":

g++ -std=c++11 -stdlib=libc++ input.cxx -o a.out

On Mavericks and Later OS X:

Starting with OS X Mavericks, libc became the default C library. Accordingly, there is no need to use the "-stdlib=" flag:

clang++ -std=c++11 input.cxx -o a.out

Building Against libstdc on OS X:

With Xcode 10 onwards, building applications against libstdc is no longer supported. Existing code compiled against libstdc will continue to function, but new code compilation is not permissible.

The above is the detailed content of When is the \'-stdlib=libstdc \' Flag Required When Compiling with GCC?. 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