When is it necessary to use the flag -stdlib=libstdc++?(什么时候需要使用标志 -stdlib=libstdc++?)
问题描述
gcc 编译时,编译器和链接器什么时候需要使用标志-stdlib=libstdc++?
When is it necessary to use use the flag -stdlib=libstdc++ for the compiler and linker when compiling with gcc?
编译器会自动使用libstdc++吗?
Does the compiler automatically use libstdc++?
我在 Ubuntu 13.10 上使用 gcc4.8.2,我想使用 c++11 标准.我已经将 -std=c++11 传递给编译器.
I am using gcc4.8.2 on Ubuntu 13.10 and I would like to use the c++11 standard. I already pass -std=c++11 to the compiler.
推荐答案
在 Linux 上:一般来说,所有常用的 linux 发行版都会默认使用 libstdc++,并且所有现代版本的 GCC 都带有支持 C++11 的 libstdc++.如果要在此处编译 c++11 代码,请使用以下方法之一:
On Linux: In general, all commonly available linux distributions will use libstdc++ by default, and all modern versions of GCC come with a libstdc++ that supports C++11. If you want to compile c++11 code here, use one of:
g++ -std=c++11 input.cxx -o a.out(通常是 GNU 编译器)g++ -std=gnu++11 input.cxx -o a.out
g++ -std=c++11 input.cxx -o a.out(usually GNU compiler)g++ -std=gnu++11 input.cxx -o a.out
在 Mavericks 之前的 OS X 上:g++ 实际上是 clang++ 的别名,Apple 的旧版本 libstdc++ 是默认值.您可以通过传递 -stdlib=libc++ 来使用 libc++(包括 c++11 库支持).如果要在此处编译 c++11 代码,请使用以下方法之一:
On OS X before Mavericks: g++ was actually an alias for clang++ and Apple's old version of libstdc++ was the default. You could use libc++ (which included c++11 library support) by passing -stdlib=libc++. If you want to compile c++11 code here, use one of:
g++ -std=c++11 -stdlib=libc++ input.cxx -o a.out(clang,不是 GNU 编译器!)g++ -std=gnu++11 -stdlib=libc++ input.cxx -o a.out(clang,不是 GNU 编译器!)clang++ -std=c++11 -stdlib=libc++ input.cxx -o a.outclang++ -std=gnu++11 -stdlib=libc++ input.cxx -o a.out
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.outclang++ -std=gnu++11 -stdlib=libc++ input.cxx -o a.out
自小牛队以来在 OS X 上:libc++ 是默认设置,您不应传递任何 -stdlib=<...> 标志.从 Xcode 10 开始,不支持 构建 libstdc++根本没有.针对 libstdc++ 构建的现有代码将继续工作,因为仍然提供 libstdc++.6.dylib,但不支持针对 libstdc++ 编译新代码.
On OS X since Mavericks: libc++ is the default and you should not pass any -stdlib=<...> flag. Since Xcode 10, building against libstdc++ is not supported at all anymore. Existing code built against libstdc++ will keep working because libstdc++.6.dylib is still provided, but compiling new code against libstdc++ is not supported.
clang++ -std=c++11 input.cxx -o a.outclang++ -std=gnu++11 input.cxx -o a.out
这篇关于什么时候需要使用标志 -stdlib=libstdc++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:什么时候需要使用标志 -stdlib=libstdc++?
基础教程推荐
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- CString 到 char* 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 初始化列表*参数*评估顺序 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
