When I compile my cuda code with cmake, I can't seem to get the following warning to go away:
当我用cmake编译cuda代码时,我似乎无法得到以下警告:
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:
main.cu:
#include <iostream>
int main(void) {
std::cout << "test" << std::endl;
}
CMakeLists.txt:
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:
如果我使用上面的CMakeLists。txt,它仍然默认使用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.
如果我添加-ccbin /usr/bin/g++到CUDA_NVCC_FLAGS来尝试和强制nvcc使用它,它仍然尝试编译成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?
根据CMake文档,这不应该使用c编译吗?
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?
有人知道这里发生了什么吗?我怎样才能使这个警告消失?这是nvcc或cmake的bug吗?
--
- - -
I have already found the following * questions and they have not solved the problem:
我已经找到了以下的*问题,他们没有解决这个问题:
- how to disable gcc warning "cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C [enabled by default]"
- 如何禁用gcc警告“cc1:警告:命令行选项‘-std=c++11’对c++ / objc++有效,但不支持c(默认启用)”
- Disable gcc warning for incompatible options
- 禁用不兼容选项的gcc警告。
1 个解决方案
#1
1
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...
当然,在把我的头发扯掉几个小时之后,我只花了5分钟就把这个问题写出来了。由于极好的……
You can't have -std=c++11
in CMAKE_CXX_FLAGS
because it seems to use that when compiling c code using nvcc.
在CMAKE_CXX_FLAGS中,不能有-std=c++11,因为在使用nvcc编译c代码时,它似乎使用了这种方法。
fixed CMakeLists.txt:
固定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 folks.
我要向cmake用户提交一个bug。
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)
编辑:这意味着如果您试图用-std=c++11编译任何cpp文件,那么您只需忍受警告(目前)
#1
1
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...
当然,在把我的头发扯掉几个小时之后,我只花了5分钟就把这个问题写出来了。由于极好的……
You can't have -std=c++11
in CMAKE_CXX_FLAGS
because it seems to use that when compiling c code using nvcc.
在CMAKE_CXX_FLAGS中,不能有-std=c++11,因为在使用nvcc编译c代码时,它似乎使用了这种方法。
fixed CMakeLists.txt:
固定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 folks.
我要向cmake用户提交一个bug。
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)
编辑:这意味着如果您试图用-std=c++11编译任何cpp文件,那么您只需忍受警告(目前)