用 g++ 编译 c++14 代码 [英] Compile c++14-code with g++

查看:63
本文介绍了用 g++ 编译 c++14 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Ubuntu 14.04 LTS 上使用 g++ 4.8.4.尝试使用 '-std=c++14' 进行编译时,出现此错误:

I'm using g++ 4.8.4 on Ubuntu 14.04 LTS. When trying to compile with '-std=c++14', I get this error:

g++: error unrecognized command line option '-std=c++14'

使用 '-std=c++11' 编译可以正常工作,所以我不确定发生了什么.g++ 真的不支持 c++14 吗?我是否使用了错误的命令行选项?

Compiling with '-std=c++11' works fine, so I'm not sure what's going on. Does g++ really have no support for c++14 yet? Am I using a wrong command line option?

我使用了sudo apt-get install g++",它应该会自动检索最新版本,对吗?

I used "sudo apt-get install g++" which should automatically retrieve the latest version, is that correct?

推荐答案

gcc 4.8.4需要在以后的版本中使用-std=c++1y,看起来从 5.2 开始你可以使用 -std=c++14.

For gcc 4.8.4 you need to use -std=c++1y in later versions, looks like starting with 5.2 you can use -std=c++14.

如果我们查看 gcc 在线文档,我们可以找到每个 gcc 版本的手册,我们可以通过查看4.9.3的方言选项GCC 4.9.3 手册 下它说:

If we look at the gcc online documents we can find the manuals for each version of gcc and we can see by going to Dialect options for 4.9.3 under the GCC 4.9.3 manual it says:

‘c++1y’

ISO C++ 标准的下一个修订版,暂定于 2014 年发布.支持是高度实验性的,并且几乎肯定会在未来的版本中以不兼容的方式发生变化.

The next revision of the ISO C++ standard, tentatively planned for 2014. Support is highly experimental, and will almost certainly change in incompatible ways in future releases.

所以直到 4.9.3 你必须使用 -std=c++1ygcc 5.2 选项 说:

So up till 4.9.3 you had to use -std=c++1y while the gcc 5.2 options say:

‘c++14’‘c++1y’

‘c++14’ ‘c++1y’

2014 ISO C++ 标准加上修订.不推荐使用名称c++1y".

The 2014 ISO C++ standard plus amendments. The name ‘c++1y’ is deprecated.

我不清楚为什么它会列在 Options Controlling C Dialect 下,但这就是当前文档的组织方式.

It is not clear to me why this is listed under Options Controlling C Dialect but that is how the documents are currently organized.

这篇关于用 g++ 编译 c++14 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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