0

I am trying to build a project from cmake on CentOS 7. The project requires C++ 17 and I'm getting this error from the build:

CMake Error at nvbench/nvbench/CMakeLists.txt:86 (target_compile_features):
  target_compile_features The compiler feature "cxx_std_17" is not known to
  CXX compiler

  "GNU"

  version 4.8.5.

L86:

target_compile_features(nvbench PUBLIC cuda_std_17 PRIVATE cxx_std_17)

Naturally, CentOS 7's g++ has version 4.8.5 and doesn't support C++ 17, but I have devtoolset 9 which has g++ version 9.3.1. I've added these lines near the top CMakeLists.txt:

set(CMAKE_C_COMPILER /opt/rh/devtoolset-9/root/bin/gcc)
set(CMAKE_CXX_COMPILER /opt/rh/devtoolset-9/root/bin/g++)

but cmake still references the default compiler and not the one in the devtoolset.

Also made sure to run with scl enable devtoolset-9 'cmake ..' but that didn't work either.

How can I fix this so cmake uses g++ in the devtooset?

codesling
  • 43
  • 6
  • *I've added these lines near the top CMakeLists.txt* Please show a [mcve]. "near" is very inexact location. Also try to remove CMakeCache.txt: – 273K Dec 19 '22 at 17:12
  • Yes I'm aware those two lines alone don't say a whole lot. Are you saying I should post the entire CMakeLists.txt (as well as the CMakeLists.txt that adds it as a subdirectory) for reproducibility? – codesling Dec 19 '22 at 17:16
  • For that error, it's enough to show from the top till `target_compile_features` and `project`. You might simplify it to 5 lines. – 273K Dec 19 '22 at 17:29
  • 1
    [That question](https://stackoverflow.com/questions/45933732/how-to-specify-a-compiler-in-cmake) and its answers describe **several** possible ways for set a compiler in CMake, and with **more details** than you show us. So, have you tried to set `CMAKE_CXX_COMPILER` and `CMAKE_C_COMPILER` variables **before** the `project()` call? Or have you tried other ways, e.g. passing these variables via `-D` option to `cmake`? – Tsyvarev Dec 19 '22 at 17:40
  • Set the compiler in a toolchain file. You probably need to repeat the cmake configuration step with a fresh directory for this to work though... – fabian Dec 20 '22 at 08:28

0 Answers0