我正在尝试将一些代码转换为使用CUDA,我认为我遇到了兼容性问题。我们使用CMake。这些是我使用的gcc和CUDA版本:
$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.5) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Tue_Jan_10_13:22:03_CST_2017
Cuda compilation tools, release 8.0, V8.0.61
在CMakeLists.txt文件中,设置为:
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
编译时,我收到此错误:
/usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h(436): error: identifier "nullptr" is undefined
/usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h(436): error: expected a ";"
/usr/include/x86_64-linux-gnu/c++/5/bits/c++config.h(200): error: expected a ";"
/usr/include/c++/5/exception(63): error: expected a ";"
/usr/include/c++/5/exception(68): error: expected a ";"
/usr/include/c++/5/exception(76): error: expected a ";"
/usr/include/c++/5/exception(83): error: expected a ";"
/usr/include/c++/5/exception(93): error: expected a "{"
...
我找到了this discussion,它说要将C ++标志更改为-std=c++98
,但是由于它广泛使用了C ++ 11代码,因此无法为该项目做些什么。这有解决方案吗?它似乎不是一个独特的问题,但我似乎无法找到解决方案...
这是我运行cmake
时的输出,所以我知道它确实使用gcc 5.4而不是另一个版本。
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found CUDA: /usr/local/cuda (found version "8.0")
-- Found OpenCV: /usr/local (found version "3.2.0")
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython2.7.so (found suitable version "2.7.12", minimum required is "2.7")
-- Found PythonInterp: /usr/bin/python2.7 (found version "2.7.12")
-- Boost version: 1.58.0
-- Found the following Boost libraries:
-- python
-- Configuring done
-- Generating
答案 0 :(得分:3)
如果您愿意需要更新版本的CMake,那么便携式解决方案就是
cmake_minimum_required(VERSION 3.1.3)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON) # not necessary, but encouraged
我大约90%确定它与v3.1.3
有关。确保您在 之前设置了任何特定目标(例如cuda_add_library
或cuda_add_executable
)。
另请注意,如果您使用传统的find_package(CUDA)
和cuda_add_library
等,则可能还需要
set(CUDA_PROPAGATE_HOST_FLAGS ON)
否则nvcc
默认情况下不会继承这些定义。
答案 1 :(得分:1)
从
进行简单的更改SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
要
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
解决了我的问题。感谢talonmies的解决方案。