Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/164.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用正确的默认g++;支持c+的版本+;17_C++_G++_C++17 - Fatal编程技术网

C++ 使用正确的默认g++;支持c+的版本+;17

C++ 使用正确的默认g++;支持c+的版本+;17,c++,g++,c++17,C++,G++,C++17,我有一个项目需要g++版本6或更低版本(默认情况下)。我多次删除了g++/gcc的版本,并多次使用updatealternations 目前我正在处理的项目需要g++7或更高版本,因为它使用c++17。其中的示例代码如下所示 std::tuple<int, std::string> xyz = std::make_tuple(1, "2"); auto [x, y] = xyz; std::cout << x << " "

我有一个项目需要g++版本6或更低版本(默认情况下)。我多次删除了g++/gcc的版本,并多次使用
updatealternations

目前我正在处理的项目需要g++7或更高版本,因为它使用c++17。其中的示例代码如下所示

std::tuple<int, std::string> xyz = std::make_tuple(1, "2");
auto [x, y] = xyz;
std::cout << x << " " << y << "\n";
There are 2 choices for the alternative g++ (providing /usr/bin/g++).
  Selection    Path            Priority   Status
------------------------------------------------------------
* 0            /usr/bin/g++-7   80        auto mode
  1            /usr/bin/g++-6   50        manual mode
  2            /usr/bin/g++-7   80        manual mode
当我跑步的时候它会工作

g++ test.cpp -o test -std=c++17
g++-7 test.cpp -o test -std=c++17
由于我的项目很大,很难找到并用g++-7替换所有的g++。请任何人提出一个如何进行这项工作的建议。当前,在运行命令sudo update alternations--config g++时,我得到以下信息:

std::tuple<int, std::string> xyz = std::make_tuple(1, "2");
auto [x, y] = xyz;
std::cout << x << " " << y << "\n";
There are 2 choices for the alternative g++ (providing /usr/bin/g++).
  Selection    Path            Priority   Status
------------------------------------------------------------
* 0            /usr/bin/g++-7   80        auto mode
  1            /usr/bin/g++-6   50        manual mode
  2            /usr/bin/g++-7   80        manual mode

[更新]项目使用单个Makefile,并使用
makecc
对其进行编译。此项目中没有使用cmake。

您没有说明项目是如何设置的。例如,它是否使用CMake?还是一堆手写的命令行?你不能只为每个项目适当地设置环境变量路径,而不干扰系统吗?很抱歉没有提及这一点。但是没有使用的cmake。它直接运行
makecc
。如果您的makefile在多个位置使用了
g++
命令,则需要修复。makefile应该在顶部附近的某个地方说些什么
CXX=/usr/bin/g++-7
,从今以后使用
$(CXX)
。更简单的方法是使用CMake工具链定义文件,如果您出于某种原因一直使用Unix makefile,请使用自己的东西来模拟它。请参见
-DCMAKE\u TOOLCHAIN\u FILE=path/to/FILE
,如果说它使用
make
,也不会告诉我们太多。同样,在几乎所有情况下都可以使用的解决方案是创建一个目录,将g++-7符号链接为g++,并在运行
make
之前将其放在PATH中的第一位。但应该有更好的选择。