Can't get rid of "warning: command line option" -std = c ++ 11 "using nvcc / CUDA / cmake

When I compile the cuda code using cmake, I cannot get the following warning:

cc1: warning: command line option ‘-std=c++11is valid for C++/ObjC++ but not for C [enabled by default]

      

I reduced the problem to compilation, not my original code. Here's a simplified (but working) example:

main.cu:

#include <iostream>

int main(void) {
    std::cout << "test" << std::endl;
}

      

CMakeLists.txt:

cmake_minimum_required(VERSION 3.0.3) 

project(a_test)

find_package(CUDA REQUIRED)

include_directories(
    /usr/local/cuda-6.5/targets/x86_64-linux/include
    )

link_directories(
    /usr/lib/x86_64-linux-gnu
    /usr/lib/python2.7/config-x86_64-linux
    )

set(CUDA_HOST_COMPILATION_CPP ON)
set(CUDA_NVCC_FLAGS -v -std=c++11 -g -Xcompiler -fexceptions -Xcompiler -fPIC)
set(CMAKE_C_FLAGS "-g -fPIC")
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11 -g -fPIC")
set(CUDA_SEPARABLE_COMPILATION ON)

set(
    SRC_FILES
    main.cu
)

cuda_add_executable(
    a_test

    ${SRC_FILES}
    )
target_link_libraries(
    a_test
    ${LD_LIBRARIES}
    )

      

If I use the above CMakeLists.txt it uses gcc by default:

#$ "/usr/bin"/gcc-4.8 -D__CUDA_ARCH__=200 -E -x c      -DCUDA_DOUBLE_MATH_FUNCTIONS  -D__CUDACC__ -D__NVCC__ -D__CUDACC_RDC__ -D__CUDANVVM__  -std=c++11 -g -fPIC -g -fexceptions -fPIC -D__CUDA_PREC_DIV -D__CUDA_PREC_SQRT -I"/usr/local/cuda-6.5/include" -I"/usr/local/cuda-6.5/targets/x86_64-linux/include" -I"/usr/local/cuda-6.5/include" "-I/usr/local/cuda-6.5/bin/../targets/x86_64-linux/include"   -m64 -g -gdwarf-2 -o "/tmp/tmpxft_00001eb1_00000000-7_main.cpp2.i" "/tmp/tmpxft_00001eb1_00000000-3_main.cudafe1.gpu"
cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C [enabled by default]

      

and if I add -ccbin /usr/bin/g++

in CUDA_NVCC_FLAGS

to try and get nvcc to use it, it still tries to compile as C.

#$ "/usr/bin"/g++ -D__CUDA_ARCH__=200 -E -x c      -DCUDA_DOUBLE_MATH_FUNCTIONS  -D__CUDACC__ -D__NVCC__ -D__CUDACC_RDC__ -D__CUDANVVM__  -std=c++11 -g -fPIC -g -fexceptions -fPIC -D__CUDA_PREC_DIV -D__CUDA_PREC_SQRT -I"/usr/local/cuda-6.5/include" -I"/usr/local/cuda-6.5/targets/x86_64-linux/include" -I"/usr/local/cuda-6.5/include" "-I/usr/local/cuda-6.5/bin/../targets/x86_64-linux/include"   -m64 -g -gdwarf-2 -o "/tmp/tmpxft_00001f27_00000000-7_main.cpp2.i" "/tmp/tmpxft_00001f27_00000000-3_main.cudafe1.gpu"
cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C [enabled by default]

      

According to CMake docs this should never be used with c compilation?

CUDA_HOST_COMPILATION_CPP (Default ON)
-- Set to OFF for C compilation of host code.

      

Does anyone know what's going on here? How can I prevent this warning? Is this a bug in nvcc or cmake?

-

I've already found the following stackoverflow related questions and they didn't solve the problem:

+3


source to share


1 answer


Of course, after hours of pulling my hair off, all it took was 5 minutes after posting the question to work out an answer. Thanks ducky ...

You can't have -std=c++11

in CMAKE_CXX_FLAGS

because it seems to be used when compiling c code using nvcc.

fixed CMakeLists.txt:



cmake_minimum_required(VERSION 3.0.3) 

project(a_test)

find_package(CUDA REQUIRED)

include_directories(
    /usr/local/cuda-6.5/targets/x86_64-linux/include
    )

link_directories(
    /usr/lib/x86_64-linux-gnu
    /usr/lib/python2.7/config-x86_64-linux
    )

set(CUDA_HOST_COMPILATION_CPP ON)
set(CUDA_NVCC_FLAGS -std=c++11 -g -Xcompiler -fexceptions -Xcompiler -fPIC)
set(CMAKE_C_FLAGS "-g -fPIC")
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-g -fPIC")
set(CUDA_SEPARABLE_COMPILATION ON)

set(
    SRC_FILES
    main.cu
)

cuda_add_executable(
    a_test

    ${SRC_FILES}
    )
target_link_libraries(
    a_test
    ${LD_LIBRARIES}
    )

      

I'm going to file a bug with the cmake people.

Edit: This means that if you are trying to compile any cpp files with -std = C ++ 11 you just have to live with the warning (for now)

+1


source







All Articles