Skip to content

Compiling with CMAKE_CXX_STANDARD=17 results in CUDA/Thrust "C++17 is not enabled" compiler warnings #27095

@patrikhuber

Description

@patrikhuber

System Information

OpenCV 4.x from a couple days ago (6eaaaa4), Windows 11, cmake 3.31.5, CUDA 12.8

Detailed description

Compiling with CMAKE_CXX_STANDARD=17 still results in CUDA/Thrust "C++17 is not enabled" compiler warnings" See below.

This is probably not an issue now as it still builds, and mixing C++14 and 17 shouldn't be a problem. But, as the warning says, it probably won't work for a lot longer, if CMAKE_CXX_STANDARD is not handled correctly throughout the OpenCV build.

Steps to reproduce

Building OpenCV with:

cmake -S ../../ -B . -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_CXX_STANDARD_REQUIRED:BOOL=ON \
-DCMAKE_CXX_EXTENSIONS:BOOL=OFF \
-DCMAKE_INSTALL_PREFIX:PATH="C:/Users/User/opencv/install/" \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_WITH_STATIC_CRT:BOOL=OFF \
-DBUILD_opencv_world:BOOL=0 \
-DWITH_CUDA:BOOL=1 \
-DOPENCV_EXTRA_MODULES_PATH:PATH="C:/Users/User/opencv_contrib/modules" \
-DCUDNN_LIBRARY:FILEPATH="C:/Program Files/NVIDIA/CUDNN/v9.8/lib/12.8/x64/cudnn.lib" \
-DCUDNN_INCLUDE_DIR:PATH="C:/Program Files/NVIDIA/CUDNN/v9.8/include/12.8" \
-DCMAKE_CUDA_ARCHITECTURES:STRING="86;89;90;100;120" \
-DCUDA_ARCH_BIN="8.6;8.9;9.0;10.0;12.0" \
-DCUDA_ARCH_PTX="12.0" \

The critical part being -DCMAKE_CXX_STANDARD=17. OpenCV's CMake configure output confirms this by showing:

--     C++ standard:                17

However during building, I get a tons of warnings where Thrust indicates that C++17 is not enabled:

[560/3092] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat_nd.cu.obj
gpu_mat_nd.cu
C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.8/include\thrust/detail/config/cpp_dialect.h:117: warning: Thrust requires at least C++ 17.C++ 14 is deprecated but still supported.C++ 14 support will be removed in a future release.Define THRUST_IGNORE_DEPRECATED_CPP_DIALECT to suppress this message

Looks like CMAKE_CXX_STANDARD=17 might not be correctly passed through somewhere?

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions