# Centos C++17安装求助

**URL:** <https://forum.freemdict.com/t/topic/15259>\
**Category:** 技术交流与词典编修\
**Created:** [2022 年9 月 10 日 00:41 UTC](https://forum.freemdict.com/t/topic/15259 "2022-09-10T00:41:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

作者： ![hkreporter](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/h/41988e/32.png) [@hkreporter](https://forum.freemdict.com/u/hkreporter)\
发布日期： [2022 年9 月 10 日 00:41 UTC](https://forum.freemdict.com/t/topic/15259/1 "2022-09-10T00:41:50Z")

</div>

试玩Taskwarrior，编译失败，提示缺乏C++17 支持  
尝试解决：  
[CentOS7安装c++17 - 简书](https://www.jianshu.com/p/e9bfdc040dc1)

设置成功，升级到c++ (GCC) 7.3.1，但仍旧提示C++17 support missing.  
[VS版本、GCC版本与C++版本的对应关系\_Captain–Jack的博客-CSDN博客\_c++11是vs哪个版本](https://blog.csdn.net/u010977122/article/details/100708274)  
应该是支持的才对。

无解。求助。

```auto
[root@localhost task-2.6.2]# c++ --version
c++ (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@localhost task-2.6.2]# cmake -DCMAKE_BUILD_TYPE=release .
-- Configuring C++17
-- System: Linux
CMake Error at cmake/CXXSniffer.cmake:11 (message):
  C++17 support missing. Try upgrading your C++ compiler. If you have a
  good reason for using an outdated compiler, please let us know at
  support@gothenburgbitfactory.org.
Call Stack (most recent call first):
  CMakeLists.txt:10 (include)

-- Configuring incomplete, errors occurred!
See also "/opt/task-2.6.2/CMakeFiles/CMakeOutput.log".
See also "/opt/task-2.6.2/CMakeFiles/CMakeError.log".

```

---

<div class="post-metadata">

作者： ![xiaoyifang](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/x/df788c/32.png) [@xiaoyifang](https://forum.freemdict.com/u/xiaoyifang)\
发布日期： [2022 年9 月 10 日 01:34 UTC](https://forum.freemdict.com/t/topic/15259/2 "2022-09-10T01:34:19Z")

</div>

> **[cmake增加-std=c++11,-std=c++14,-std=c++17选项\_直播技术开发交流的博客-CSDN博客\_-std=c++](https://blog.csdn.net/lsheevyfg/article/details/119795716)**
>
> cmake生成makefile增加c++版本选项，命令如下：# 增加-std=gnu++11cmake . -DCMAKE\_CXX\_STANDARD=11 \<path-to-source\># 增加-std=gnu++14cmake . -DCMAKE\_CXX\_STANDARD=14 \<path-to-source\># 增加-std=gnu++17cmake . -DCMAKE\_CXX\_STANDARD=17 \<path-to-source\>...

---

<div class="post-metadata">

作者： ![hkreporter](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/h/41988e/32.png) [@hkreporter](https://forum.freemdict.com/u/hkreporter)\
发布日期： [2022 年9 月 10 日 03:49 UTC](https://forum.freemdict.com/t/topic/15259/3 "2022-09-10T03:49:26Z")

</div>

还是报错：

```auto
cmake . -DCMAKE_CXX_STANDARD=17 /opt/rh/devtoolset-7/

```

报错：

```auto
[root@localhost task-2.6.2]# cmake . -DCMAKE_CXX_STANDARD=17 /opt/rh/devtoolset-7/
CMake Warning:
  Ignoring extra path from command line:

   "/opt/rh/devtoolset-7/"

-- Configuring C++17
-- System: Linux
CMake Error at cmake/CXXSniffer.cmake:11 (message):
  C++17 support missing. Try upgrading your C++ compiler. If you have a
  good reason for using an outdated compiler, please let us know at
  support@gothenburgbitfactory.org.
Call Stack (most recent call first):
  CMakeLists.txt:10 (include)

```

去掉路径也不行：

```auto
-- Configuring C++17
-- System: Linux
CMake Error at cmake/CXXSniffer.cmake:11 (message):
  C++17 support missing. Try upgrading your C++ compiler. If you have a
  good reason for using an outdated compiler, please let us know at
  support@gothenburgbitfactory.org.
Call Stack (most recent call first):
  CMakeLists.txt:10 (include)

-- Configuring incomplete, errors occurred!
See also "/opt/task-2.6.2/CMakeFiles/CMakeOutput.log".
See also "/opt/task-2.6.2/CMakeFiles/CMakeError.log".

```

---

<div class="post-metadata">

作者： ![atauzki](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/atauzki/32/1365_2.png) [@atauzki](https://forum.freemdict.com/u/atauzki)\
发布日期： [2022 年9 月 10 日 10:20 UTC](https://forum.freemdict.com/t/topic/15259/4 "2022-09-10T10:20:31Z")

</div>

指定g++的绝对路径，cmake -DCMAKE\_CXX\_COMPILER=path/to/g++

/path/to/g++换成你安装的g++的路径

---

<div class="post-metadata">

作者： ![hkreporter](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/h/41988e/32.png) [@hkreporter](https://forum.freemdict.com/u/hkreporter)\
发布日期： [2022 年9 月 10 日 11:08 UTC](https://forum.freemdict.com/t/topic/15259/5 "2022-09-10T11:08:16Z")

</div>

是这样写吗？  
cmake -DCMAKE\_CXX\_COMPILER=/usr/bin/g++

还是不行：

```auto

root@localhost task-2.6.2]# cmake -DCMAKE_CXX_COMPILER=/usr/bin/g++
CMake Warning:
  No source or binary directory provided. Both will be assumed to be the
  same as the current working directory, but note that this warning will
  become a fatal error in future CMake releases.

-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring C++17
-- System: Linux
-- Performing Test _HAS_CXX17
-- Performing Test _HAS_CXX17 - Failed
CMake Error at cmake/CXXSniffer.cmake:11 (message):
  C++17 support missing. Try upgrading your C++ compiler. If you have a
  good reason for using an outdated compiler, please let us know at
  support@gothenburgbitfactory.org.
Call Stack (most recent call first):
  CMakeLists.txt:10 (include)

-- Configuring incomplete, errors occurred!
See also "/opt/task-2.6.2/CMakeFiles/CMakeOutput.log".
See also "/opt/task-2.6.2/CMakeFiles/CMakeError.log".

```

---

<div class="post-metadata">

作者： ![atauzki](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/atauzki/32/1365_2.png) [@atauzki](https://forum.freemdict.com/u/atauzki)\
发布日期： [2022 年9 月 10 日 12:26 UTC](https://forum.freemdict.com/t/topic/15259/6 "2022-09-10T12:26:22Z")

</div>

你4.8哪来的c++17，我说的是你安装的g++7的路径

---

<div class="post-metadata">

作者： ![demo](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/d/e47774/32.png) [@demo](https://forum.freemdict.com/u/demo)\
发布日期： [2022 年9 月 10 日 14:38 UTC](https://forum.freemdict.com/t/topic/15259/7 "2022-09-10T14:38:29Z")

</div>

以下是经过验证的可行方法，可以试一下:

1、安装gcc安装包的镜像源  
yum install centos-release-scl

2、安装gcc10和g++10  
yum install devtoolset-10

3、针对当前shell启动新版本编译器  
scl enable devtoolset-10 bash

4、开始 cmake 命令生成 makefile  
cmake 编译参数

5、开始编译  
make

说明：第三步，就是切换编译为 gcc10, 而不是使用默认的 4.8.5. cmake 还是原来的参数，不用指定编译器就用当前scl环境的 gcc10

---

<div class="post-metadata">

作者： ![hkreporter](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/h/41988e/32.png) [@hkreporter](https://forum.freemdict.com/u/hkreporter)\
发布日期： [2022 年9 月 11 日 01:25 UTC](https://forum.freemdict.com/t/topic/15259/8 "2022-09-11T01:25:48Z")

</div>

4、开始 cmake 命令生成 makefile  
cmake 编译参数  
请教这一步该怎么写？

[Taskwarrior - What’s next? - Taskwarrior](https://taskwarrior.org/download/)

用官方的做法会报错：

```auto
[xxx@localhost ~]$ cmake -DCMAKE_BUILD_TYPE=release .
CMake Warning:
  Ignoring extra path from command line:

   "."

CMake Error: The source directory "/home/xxx" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
```

---

<div class="post-metadata">

作者： ![atauzki](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/atauzki/32/1365_2.png) [@atauzki](https://forum.freemdict.com/u/atauzki)\
发布日期： [2022 年9 月 11 日 07:10 UTC](https://forum.freemdict.com/t/topic/15259/9 "2022-09-11T07:10:27Z")

</div>

目录都没切，当然编译不了
