Home >Backend Development >C++ >When to Specify \'-stdlib=libstdc \' when Compiling with GCC?

When to Specify \'-stdlib=libstdc \' when Compiling with GCC?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-24 02:20:02543browse

When to Specify

When to Use -stdlib=libstdc

When compiling with gcc, the -stdlib=libstdc flag specifies the C standard library to use. In most cases, the compiler will automatically use libstdc , the GNU C library, as the default. However, there are instances where it may be necessary to explicitly specify -stdlib=libstdc .

Compiler-Specific Behavior

On Linux, all major distributions use libstdc as the default C library, and recent GCC versions support C 11 by default. To compile C 11 code, you can use either:

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

On OS X prior to Mavericks, g was an alias for clang , and Apple's older libstdc was the default. To use libc , which includes C 11 library support, pass -stdlib=libc . Compilation options include:

  • g -std=c 11 -stdlib=libc input.cxx -o a.out
  • g -std=gnu 11 -stdlib=libc input.cxx -o a.out
  • clang -std=c 11 -stdlib=libc input.cxx -o a.out
  • clang -std=gnu 11 -stdlib=libc input.cxx -o a.out

OS X Mavericks and Later

Since OS X Mavericks, libc has become the default C library. You should refrain from using the -stdlib= flag in this case. Notably, Xcode 10 and later no longer support compiling against libstdc .

Recommended Compilation Options

  • Linux: Use g -std=c 11 input.cxx -o a.out or g -std=gnu 11 input.cxx -o a.out
  • OS X (before Mavericks): Use g -std=c 11 -stdlib=libc input.cxx -o a.out or clang -std=c 11 -stdlib=libc input.cxx -o a.out
  • OS X (Mavericks and later): Use clang -std=c 11 input.cxx -o a.out or clang -std=gnu 11 input.cxx -o a.out

The above is the detailed content of When to Specify \'-stdlib=libstdc \' 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