【问题标题】:g++ 5.4.0 - unable to use C++14 standardg++ 5.4.0 - 无法使用 C++14 标准
【发布时间】:2016-10-27 19:23:07
【问题描述】:

我最近在 Windows 上使用 Cygwin 安装了 gcc 5.4.0,因为我想测试 g++ 的 C++14 标准特性。当我尝试编译时,出现以下错误:

$ g++-5.4.0 -std=c++14 test.cpp
-bash: g++-5.4.0: command not found

这是我在 test.cpp 中编写的代码:

#include <iostream>

int main()
{
    auto lambda = [](auto x){ return x; };
    std::cout << lambda("Hello generic lambda!\n");
    return 0;
}

可能是什么问题?我还尝试在命令中将C++14 替换为C++11,但得到了同样的错误。

【问题讨论】:

  • 错误是你的路径中没有g++-5.4.0,并不是你的GCC副本不支持C++14。

标签: c++11 gcc cygwin c++14


【解决方案1】:

当 Cygwin 安装 g++ 版本(在您的情况下为 5.4.0)时,它会将 g++ 可执行文件放在您的 PATH 变量中。但是安装名称只是g++.exe,所以可以这样调用程序:

g++ -std=c++14 test.cpp

如果您真的想用 g++-5.4.0 调用编译器,您可以将实际的 g++ 可执行文件符号链接到该名称:

ln -s /usr/bin/g++.exe /usr/bin/g++-5.4.0.exe

那么您将能够从命令行使用 g++ 或 g++-5.4.0 调用程序:

g++-5.4.0 -std=c++14 test.cpp
g++ -std=c++14 test.cpp

【讨论】:

  • 感谢您的准确回答!我最近开始使用 g++,因此提出了一个幼稚的问题。
猜你喜欢
  • 2021-07-14
  • 1970-01-01
  • 2015-10-14
  • 2013-10-05
  • 2015-11-05
  • 1970-01-01
  • 1970-01-01
  • 2013-12-24
  • 1970-01-01
相关资源
最近更新 更多