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
Release: 2024-10-24 01:27:29
Original
224 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

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!

source:php
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template