我正在尝试使用cuda 7.5.18和gcc 5.4.0编译c++
nvcc
文件并遇到错误。采用以下简单示例:
#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)。
我可以做些什么来解决这个问题?
答案 0 :(得分:-2)
错误的原因尚不清楚,但您可以轻松解决lambda:
int main()
{
int a,b,c,x;
printf("Enter a & b \n"); //printing
scanf("%d %d, &a,&b");
printf("1. add \n 2. sub \n 3. multiply \n 4. div \n 5. mod \n 6. and \n 7. or\n 8. not \n 9. xor \n");
printf("Enter your choice \n");
scanf("%d, &x");
switch(x)
{
case 1: c=a+b;
break;
case 2: c=a-b;
break;
case 3: c=a*b;
break;
case 4: c=a/b;
break;
case 5: c=a%b;
break;
case 6: c=a && b;
break;
case 7: c=a || b;
break;
case 8: c=~a;
break;
case 9: c=a^b;
break;
default: printf("Make correct choice\n");
}
printf("result is: %d",c);
return 0;
}