Error while using CUDA and C++11(使用 CUDA 和 C++11 时出错)
问题描述
我正在使用 CUDA 4.1 和 GCC 4.5 ...(终于!CUDA 支持 GCC 4.5,但仍在等待 GCC 4.6).无论如何,是否可以在 CUDA 4.1 中使用 C++11?
I am using CUDA 4.1 and GCC 4.5 ... (FINALLY! CUDA supports GCC 4.5, but still waiting for GCC 4.6). Anyways, is it possible to use C++11 with the CUDA 4.1?
我尝试过:
--compiler-options "-std=c++0x"
到 nvcc,它会向我抛出一堆错误:
to nvcc and it throws a bunch of errors at me:
/usr/include/c++/4.5/exception_ptr.h(100): error: copy constructor for class "std::__exception_ptr::exception_ptr" may not have a parameter of type "std::__exception_ptr::exception_ptr"
/usr/include/c++/4.5/exception_ptr.h(100): error: expected a ")"
/usr/include/c++/4.5/exception_ptr.h(110): error: expected a ")"
/usr/include/c++/4.5/exception_ptr.h(132): error: identifier "type_info" is undefined
/usr/include/c++/4.5/exception_ptr.h(101): error: identifier "__o" is undefined
/usr/include/c++/4.5/exception_ptr.h(112): error: expected a ">"
/usr/include/c++/4.5/exception_ptr.h(112): error: identifier "__o" is undefined
/usr/include/c++/4.5/nested_exception.h(62): error: expected a ";"
/usr/include/c++/4.5/nested_exception.h(64): error: expected a ";"
/usr/include/c++/4.5/nested_exception.h(77): error: member function "std::nested_exception::~nested_exception" may not be redeclared outside its class
/usr/include/c++/4.5/nested_exception.h(77): error: function "std::<error>" may not be initialized
/usr/include/c++/4.5/nested_exception.h(77): error: expected an expression
/usr/include/c++/4.5/nested_exception.h(82): error: expected a ")"
/usr/include/c++/4.5/nested_exception.h(110): error: expected a ")"
/usr/include/c++/4.5/nested_exception.h(115): error: expected a ")"
/usr/include/c++/4.5/nested_exception.h(122): error: expected a ")"
/usr/include/c++/4.5/nested_exception.h(127): error: expected a ")"
/usr/include/c++/4.5/nested_exception.h(127): error: function template "std::__throw_with_nested" has already been defined
/usr/include/c++/4.5/bits/cpp_type_traits.h(180): error: identifier "char16_t" is undefined
/usr/include/c++/4.5/bits/cpp_type_traits.h(187): error: identifier "char32_t" is undefined
/usr/include/c++/4.5/bits/cpp_type_traits.h(187): error: class "std::__is_integer<<error-type>>" has already been defined
21 errors detected in the compilation of "/tmp/tmpxft_00000ef2_00000000-4_test_cuda.cpp1.ii".
示例 test.cu
#include <cuda.h>
__host__ void test() {
// nothing in method
}
编译良好:
nvcc -c -o test.o test.cu
但不使用 C++0x
nvcc -c -o test.o test.cu --compiler-options "-std=c++0x"
推荐答案
不,在这个答案中,nvcc
不支持 c++11 结构,即使它们被宿主编译器支持.
No, as of this answer, nvcc
does not support c++11 constructs, even if they are supported by the host compiler.
它不像将 -std=c++0x
传递给主机编译器那么简单的原因是 nvcc
必须解析整个代码为了将它分成 __host__
和 __device__
两半.这个预处理发生在主机编译器被提供任何代码之前,所以 nvcc
的解析器需要能够 grok c++11 才能工作.
The reason it isn't as simple as passing -std=c++0x
to the host compiler is that nvcc
has to parse the entirety of the code in order to split it into its __host__
and __device__
halves. This preprocess happens before the host compiler is presented with any code at all, so nvcc
's parser needs to be able to grok c++11 for it to work.
这篇关于使用 CUDA 和 C++11 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 CUDA 和 C++11 时出错
基础教程推荐
- Windows Media Foundation 录制音频 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 从 std::cin 读取密码 2021-01-01