gpt4 book ai didi

c++ - CUDA 8 编译错误 -std=gnu++11

转载 作者:搜寻专家 更新时间:2023-10-31 00:53:57 41 4
gpt4 key购买 nike

我正在尝试转换一些代码以使用 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

最佳答案

如果您愿意需要更新版本的 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_librarycuda_add_executable) 之前设置此项。

另请注意,如果您使用的是传统的 find_package(CUDA)cuda_add_library 等,您可能还需要

set(CUDA_PROPAGATE_HOST_FLAGS ON)

否则 nvcc 默认不继承这些定义。

关于c++ - CUDA 8 编译错误 -std=gnu++11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46901515/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com