Reputation: 491
I'm using CMake to configure a CUDA/C++ project. Some of the files compiled with NVCC require C++ 17 features. To enable those, I would use:
cmake_minimum_required(VERSION 3.19)
project(RISA LANGUAGES CXX CUDA)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CUDA_STANDARD 17)
which results in an error message:
Target "RISA" requires the language dialect "CUDA17" (with compiler extensions), but CMake does not know the compile flags to use to enable it.
Double checking the CMAKE_CUDA_COMPILE_FEATURES
variable reveals cuda_std_03 cuda_std_11 cuda_std_14
. For some reason, CMake doesn't seem to know about anything past C++14 regarding CUDA.
I'm running ubuntu 20.04 with
What can I do to get C++17 configured and compiled with this setup?
I know about this question - however the solution to just compile cuda files with C++14 does not suffice for me.
Upvotes: 4
Views: 7481
Reputation: 491
As is turns out, CMake was not using the correct nvcc
binary.
In my case, I've had two versions of nvcc on the system:
nvcc v10.1.243
in /usr/bin
andnvcc v11.2.152
in /usr/local/cuda-11.2/bin
In my CMake configuration,
CUDA_NVCC_EXECUTABLE
was set to /usr/local/cuda-11.2/bin
, butCMAKE_CUDA_COMPILER
was set to the older version in /usr/bin
.After setting CMAKE_CUDA_COMPILER
to the correct path, CMake was able to detect nvcc 11.2.152
and could apply the C++17 standard.
Upvotes: 7