When I compile my cuda code with cmake, I can't seem to get the following warning to go away:
cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C [enabled by default]
I have reduced the problem to the compilation, not my source code. Here is 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 still defaults to using gcc:
#$ "/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++
to CUDA_NVCC_FLAGS
to try and force 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 the CMake docs this should never be using c compilation anyway?
CUDA_HOST_COMPILATION_CPP (Default ON)
-- Set to OFF for C compilation of host code.
Does anyone know what on earth is happening here? How can I make this warning go away? Is this a bug in nvcc or cmake?
--
I have already found the following stackoverflow questions and they have not solved the problem:
Of course, after hours of tearing my hair out, all it took was 5 minutes after posting the question to work out the answer. Thanks ducky...
You can't have
-std=c++11
inCMAKE_CXX_FLAGS
because it seems to use that when compiling c code using nvcc.fixed CMakeLists.txt:
I'm going to file a bug with the cmake folks.
Edit: this means that if you are trying to compile any cpp files with -std=c++11, you just have to put up with the warning (for now)