获取c ++ 11 - 兼容的编译器 [英] getting c++11 - compliant compiler

查看:305
本文介绍了获取c ++ 11 - 兼容的编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这看起来像是一个巨大的混乱。

我所需要的是一个实现C ++ 11的编译器,所以我可以使用< chrono>



目前,我通过调用G ++来构建程序,但是当我通过 $ g ++检查版本时-v ,我获得:


gcc 4.2.1版(基于Apple Inc. build 5658) LLVM build
2336.11.00)




发生了什么事?我使用G ++? GCC? LLVM?我甚至不知道。他们是同一件事吗?





现在我正在尝试通过 gnu.org ,但我不知道什么指南正在谈论。我从来没有见过这么多首字母缩略词,我不知道。



为什么这么复杂?所有这些版本,其中一些只实现一些部分的C ++ 11,而不是其他的?

解决方案

以下是OS X上的情况。



C ++编译器默认安装。

  [5:49 pm] [wlynch @ watermelon〜] g ++ --version 
i686 -apple-darwin11-llvm-g ++ - 4.2(GCC)4.2.1(基于Apple Inc.构建5658)(LLVM build 2336.11.00)

[5:49 pm] [wlynch @ watermelon〜 ] clang ++ --version
Apple LLVM版本4.2(clang-425.0.24)(基于LLVM 3.2svn)

g ++正在运行llvm-gcc,这是gcc前端,然后是llvm后端。



clang ++正在运行clang,然后是llvm后端。



如果你想在OS X上安装C ++ 11编译器而不安装其他软件包,你唯一的选择是使用clang编译器。 p>

必要的标志是:

  clang ++ -stdlib = libc ++ -std = gnu ++ 11 

描述我通过的两个标志:




  • -stdlib = libc ++ 使用libc ++标准库,而不是gnu libstdc ++。在OS X上,libc ++版本有c ++ 11支持。

  • -std = gnu ++ 11 告诉编译器支持c ++ 11代码功能,如lambdas和枚举类。您也可以传递 -std = c ++ 11 ,这是类似的,但不启用一些通常预期的gnu扩展。



OS X 10.9的更新:从OS X Mavericks开始,g ++和clang ++实际上都使用clang 。唯一的区别是,g ++会暗示 -stdlib = libstdc ++ ,clang ++意味着 -stdlib = libc ++ 。所以,在小牛,如果你想使用C ++ 11,你可以按照上面的建议,或只是做:

  clang ++ -std = gnu ++ 11 

更新OS X 10.10 :从OS X Yosemite开始,g ++仍然诡计多端。但是,在默认情况下不再使用libstdc ++。两者现在都在libc ++上。


This all seems like a colossal mess.
All I want is a compiler that implements C++11, so I can use <chrono>. But I'm so confused from the very beginning.

Currently, I build programs by invoking G++, but when I check the version via $ g++ -v, I get:

gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)


What's going on? Am I using G++? GCC? LLVM? I don't even know. Are they the same thing?


So now I'm trying to build and download GCC 4.7 via gnu.org, but I have no idea what any of the guides are talking about. I've never seen so many acronyms for things I dont know.

Why is this so complicated? What's with all those versions, with some of them only implementing some parts of C++11 and not others?

解决方案

Here's the situation on OS X.

There are two C++ compilers installed by default.

[5:49pm][wlynch@watermelon ~] g++ --version
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)

[5:49pm][wlynch@watermelon ~] clang++ --version
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)

g++ is running llvm-gcc, which is the gcc frontend, and then the llvm backend.

clang++ is running clang, which is the clang frontend and then the llvm backend.

If you want a C++11 compiler on OS X without installing other packages, your only option is to use the clang compiler.

The flags necessary are:

clang++ -stdlib=libc++ -std=gnu++11

To describe the two flags I'm passing:

  • -stdlib=libc++ uses the libc++ standard library, instead of the gnu libstdc++. On OS X, the libc++ version has c++11 support. The gnu libstdc++ one does not.
  • -std=gnu++11 tells the compiler to support c++11 code features, like lambdas and enum class. You can also pass -std=c++11, which is similar, but does not enable some commonly expected gnu extensions.

Update for OS X 10.9: As of OS X Mavericks, both g++ and clang++ are actually using clang. The only difference, is that g++ will imply -stdlib=libstdc++ and clang++ will imply -stdlib=libc++. So, on Mavericks, if you'd like to use C++11, you can follow the above advice, or just do:

clang++ -std=gnu++11

Update for OS X 10.10: As of OS X Yosemite, g++ is still clang in disguise. However, neither uses libstdc++ by default anymore. Both are now on libc++.

这篇关于获取c ++ 11 - 兼容的编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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