【发布时间】:2012-01-29 21:52:45
【问题描述】:
我正在使用 CUDA 4.1 和 GCC 4.5 ...(终于!CUDA 支持 GCC 4.5,但仍在等待 GCC 4.6)。无论如何,是否可以在 CUDA 4.1 中使用 C++11?
我尝试过:
--compiler-options "-std=c++0x"
到 nvcc,它会向我抛出一堆错误:
/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"
【问题讨论】:
-
只是编译器选项导致了问题,还是您使用了特定的 c++0x 功能?
-
我的 test_cuda.cu 没有代码。它只有一个功能,例如 test_cuda() {}
-
不。没有使用 extern "C" .. 编译 C++ 代码。
-
您必须在答案中添加一些代码。仅通过查看错误日志很难知道发生了什么问题。
-
使用 CUDA 6 检查我的解决方案:stackoverflow.com/questions/25941117/c11-standard-with-cuda-6-0