什么时候需要使用标志 -stdlib=libstdc++? [英] When is it necessary to use the flag -stdlib=libstdc++?

查看:47
本文介绍了什么时候需要使用标志 -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.out
  • clang++ -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.out
  • clang++ -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.out
  • clang++ -std=gnu++11 input.cxx -o a.out

这篇关于什么时候需要使用标志 -stdlib=libstdc++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆