我试图用cuda 7.5.18和gcc 5.4.0用nvcc编译一个c++文件,但遇到了错误。举个简单的例子:
#include <thrust/functional.h>
struct test_struct {
//..
}
void f(test_struct& a) {
//..
}
int main() {
test_struct a;
std::function<void()> bound_f = std::bind(f, std::ref(a));
}使用nvcc -c -std=c++11 test.cu -o test.o编译此代码会导致以下错误输出:
/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/c++/functional(78): error: class "test_struct" has no member "result_type"
detected during:
instantiation of class "std::_Maybe_get_result_type<_Functor, void> [with _Functor=test_struct]"
(86): here
instantiation of class "std::_Weak_result_type_impl<_Functor> [with _Functor=test_struct]"
(184): here
instantiation of class "std::_Weak_result_type<_Functor> [with _Functor=test_struct]"
(264): here
instantiation of class "std::_Reference_wrapper_base_impl<true, true, _Tp> [with _Tp=test_struct]"
(283): here
instantiation of class "std::_Reference_wrapper_base<_Tp> [with _Tp=test_struct]"
(399): here
instantiation of class "std::reference_wrapper<_Tp> [with _Tp=test_struct]"
test.cu(14): here
/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/c++/functional(266): error: class "test_struct" has no member "argument_type"
detected during:
instantiation of class "std::_Reference_wrapper_base_impl<true, true, _Tp> [with _Tp=test_struct]"
(283): here
instantiation of class "std::_Reference_wrapper_base<_Tp> [with _Tp=test_struct]"
(399): here
instantiation of class "std::reference_wrapper<_Tp> [with _Tp=test_struct]"
test.cu(14): here
/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/c++/functional(267): error: class "test_struct" has no member "first_argument_type"
detected during:
instantiation of class "std::_Reference_wrapper_base_impl<true, true, _Tp> [with _Tp=test_struct]"
(283): here
instantiation of class "std::_Reference_wrapper_base<_Tp> [with _Tp=test_struct]"
(399): here
instantiation of class "std::reference_wrapper<_Tp> [with _Tp=test_struct]"
test.cu(14): here
/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/c++/functional(268): error: class "test_struct" has no member "second_argument_type"
detected during:
instantiation of class "std::_Reference_wrapper_base_impl<true, true, _Tp> [with _Tp=test_struct]"
(283): here
instantiation of class "std::_Reference_wrapper_base<_Tp> [with _Tp=test_struct]"
(399): here
instantiation of class "std::reference_wrapper<_Tp> [with _Tp=test_struct]"
test.cu(14): here
5 errors detected in the compilation of "/tmp/tmpxft_00003b29_00000000-7_test.cpp1.ii".我找不到任何与error: ... has no member "second_argument_type"等行相关的nvcc,所以我完全一无所知。显然,不知何故找不到std::function的类成员(参见here)。
我能做些什么来解决这个问题?
发布于 2016-07-22 17:52:38
错误的原因尚不清楚,但您可以轻松地使用lambda:
std::function<void()> bound_f = [&a](){ return f(a); };https://stackoverflow.com/questions/38523067
复制相似问题