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

jeremy

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:

jeremy

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 in CMAKE_CXX_FLAGS because it seems to use that 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 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)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Can't seem to get rid of NonUniqueObjectException

From Dev

Ace Editor: Can't get rid of Marker

From Dev

Can't get rid of extra spaces in java

From Dev

HTML with entity (can't get rid of ]>)

From Dev

can't get rid of right margin

From Dev

Can't get rid of the fill at (n,n)

From Dev

Can't get rid of extra spaces in java

From Dev

Can't get rid of fake floppy drive

From Dev

Can't get rid of GPG error in apt

From Dev

Can't get rid of BluejeansHelper.log

From Dev

Can't get rid of item in Visual Studio 2015

From Java

Can't get rid of missing manifest.json error

From Dev

Can't get rid of extra space between 2 lines

From Dev

Can't get rid of jitter while dragging the left border of a window

From Dev

Can't get rid of desktop.ini file in Unity project

From Dev

Can't get rid of TypeError: 'str' object is not callable

From Dev

Can't get rid of whitespace at bottom of css parallax page

From Dev

Installed babylon in Firefox, now I can't get rid of it

From Dev

Can't get rid of mysterious outdated git installation on OS X

From Dev

Scrollbar appears when centering vertically and horizontally, can't get rid of it

From Dev

non duplicate multiple SQL records I can't get rid of

From Dev

Can't get rid of white spaces on sides of header

From Dev

Can't get rid of trash while overloading operator << in C++

From Dev

Can't get rid of whitespace at bottom of css parallax page

From Dev

Can't get rid of scheduled push notifications - iOS

From Dev

Can't get rid of blank php page after submission form

From Dev

Can't get rid of white margin on div's

From Dev

can't get rid of gap between header and body

From Dev

awk - deleted a field but can't get rid of it's delimiter

Related Related

HotTag

Archive