2

In CMakeList.txt I do want to add the -std=g++0x to the g++ options like this: set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x)

However all the CMAKE_CXX_FLAGS are passed on to nvcc as well, via the -Xcompiler flag (which is done automatically). However nvcc doesn't work with the gnu++0x standard.

Is there a way of passing the flag to g++ but not to nvcc

The compiler is specified by

if(CUDA_NVCC_HOST_COMPILER)
    list(APPEND CUDA_NVCC_FLAGS "--compiler-bindir=${CUDA_NVCC_HOST_COMPILER}")
endif(CUDA_NVCC_HOST_COMPILER)
Michael
  • 1,464
  • 1
  • 20
  • 40
  • 1
    What CUDA version do you have? Afaik C++11 is supported since CUDA 7. – BlameTheBits May 24 '17 at 10:30
  • 1
    check this https://stackoverflow.com/a/23995391/1418828 – xiaobing May 24 '17 at 10:47
  • @Shadow nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2013 NVIDIA Corporation Built on Wed_Jul_17_18:36:13_PDT_2013 Cuda compilation tools, release 5.5, V5.5.0 – Michael May 24 '17 at 11:08
  • 3
    @Michael year 2013 was 4 years ago. It's an entire epoch in software development. Nvidia did not support C++11 back then. Even GCC did not support it fully. You should upgrade. – Ivan Aksamentov - Drop May 24 '17 at 11:45

1 Answers1

2

From the FindCUDA documentation:

CUDA_PROPAGATE_HOST_FLAGS (Default ON)
-- Set to ON to propagate CMAKE_{C,CXX}_FLAGS and their configuration
   dependent counterparts (e.g. CMAKE_C_FLAGS_DEBUG) automatically to the
   host compiler through nvcc's -Xcompiler flag.  This helps make the
   generated host code match the rest of the system better.  Sometimes
   certain flags give nvcc problems, and this will help you turn the flag
   propagation off.  This does not affect the flags supplied directly to nvcc
   via CUDA_NVCC_FLAGS or through the OPTION flags specified through
   CUDA_ADD_LIBRARY, CUDA_ADD_EXECUTABLE, or CUDA_WRAP_SRCS.  Flags used for
   shared library compilation are not affected by this flag.

So, to fix your problem, just put

set(CUDA_PROPAGATE_HOST_FLAGS FALSE)

near the start of your CMake script.

  • @MultipleMonmials your answer is useful, but it didn't solve the problem. I did set the `-std` switch on a target by target basis using `target_compile_options( PUBLIC -std=c++11)` – Michael Jul 13 '17 at 16:14