0

I am trying to compile a c++ file with nvcc using cuda 7.5.18 and gcc 5.4.0 and am running into errors. Take the following simple example:

#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));
}

Compiling this code with nvcc -c -std=c++11 test.cu -o test.o results in the following error output:

/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".

I can't find anything nvcc related with the lines error: ... has no member "second_argument_type" and so on, so I am completely clueless. Apparently the class members of std::function are somehow not found (see here).

What can I do to work around this issue?

janoliver
  • 7,744
  • 14
  • 60
  • 103
  • 1
    Your code doesn't make much sense. If you are using `function` and friends from the C++ standard library, why is there no `#include ` anywhere? And why are you importing `thrust::functional`? The two are not interchangeable.... – talonmies Jul 22 '16 at 10:19
  • is included via the . Also, this is just an MWE and I'm not claiming the code makes sense. I'm just running into these errors trying to compile a larger project based on cuda. – janoliver Jul 22 '16 at 10:36
  • No matter what I do to your code (with the obvious errors missing), I can't reproduce any sort of compile error using g++ 4.8 and the CUDA 7.5 release toolkit. This looks like a simple case of CUDA not supporting gcc 5. Upgrade to the CUDA 8 RC candidate or downgrade to a supported compiler – talonmies Jul 22 '16 at 10:41
  • Hi, that might be the reason, as indicated [here](http://docs.nvidia.com/cuda/cuda-installation-guide-linux/) cuda requires gcc-4.x. I will try. Thank you! – janoliver Jul 22 '16 at 10:46
  • Turns out compilation works with gcc-4.9. If you could formulate your comment as an answer, I'll accept ist. – janoliver Jul 22 '16 at 12:09
  • The question is already closed as a duplicate. There is no way to add an answer – talonmies Jul 22 '16 at 12:20

1 Answers1

-2

The reason of error is not clear but you can easy work around with lambda:

std::function<void()> bound_f = [&a](){ return f(a); };
Andrei
  • 19
  • 1
  • 3