使用CUDA和C ++ 11时出错 [英] Error while using CUDA and C++11
问题描述
我使用CUDA 4.1和GCC 4.5 ...(FINALLY!CUDA支持GCC 4.5,但仍在等待GCC 4.6)。无论如何,是否可以使用C ++ 11与CUDA 4.1?
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
But not with 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
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时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!