Compile c++14-code with g++(用 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++1y 而 gcc 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 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用 g++ 编译 c++14 代码
基础教程推荐
- 这个宏可以转换成函数吗? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
