-2

I am working on porting parts of the boost library to compile under cuda / nvcc as device functions. This involves using the thrust library for some things like iterators, arrays, etc. One issue I am finding is a compile error in the thrust library such as:

    C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\include\thrust/iterator/iterator_traits.h(66): error : namespace "boost::std" has no member "ptrdiff_t"

which is triggered by the line in thrust:

   typedef std::ptrdiff_t difference_type;

I can fix this by adding the scope operator :: ahead of the std lib call like:

   typedef ::std::ptrdiff_t difference_type;

but clearly it is not okay to modify thrust.

Does anyone know why I am getting this issue? i.e. why does the thrust header iterator_traits.h search for std::ptrdiff_t inside the namespace boost::std rather than std? Is there a way to reverse this before I include the thrust header?

It is not easy to provide a minimal working example here due to the nature of porting a large library like boost.

Thanks!

4
  • Include the thrust headers before the boost ones? Also, are you using using namespace directives? Commented Dec 28, 2018 at 1:05
  • I'm amending the thousands of boost include files to be device compatible. So the thrust includes are deep inside the body of boost. Boost uses lots of using namespace directives. Commented Dec 28, 2018 at 1:09
  • That won't work and it is futile to try Commented Dec 28, 2018 at 7:31
  • The device port is already working for some special functions. I have hope but agree it is pretty ambitious. Commented Dec 28, 2018 at 19:08

1 Answer 1

4

I can only guess here, but my best guess is that for some reason there is a missing closing curly brace to close the boost namespace somewhere before the std namespace is opened, probably by including a standard library header. This then causes the namespace boost::std to exist so the compiler looks in that sub-namespace for std::ptrdiff_t as the boost namespace is currently open.

E.g. compiling the following source file with gcc

#include <cstddef>

namespace foo {

// this creates a namespace ::foo::std
#include <typeinfo>

}

namespace foo {
    using difference_type = std::ptrdiff_t;
}

also prints

prog.cc:11:34: error: 'ptrdiff_t' in namespace 'foo::std' does not name a type
   11 |     using difference_type = std::ptrdiff_t;
      |                                  ^~~~~~~~~

as you can also see here.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you - this was it. Much appreciated!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.