Compiler errors when including both OptiX and Thrust

I want to use both OptiX and Thrust in my application.
But I get a lot of compiler errors ("‘cudaError_t’" does not name a type" etc.) having the following order of includes:

#include <optix_world.h>
#include <thrust/device_ptr.h>

If I swap those two lines everything compiles successfully:

#include <thrust/device_ptr.h>
#include <optix_world.h>

When I investigated that issue I found out that in optixu/optixu_vector_types.h the following lines cause the problem:

namespace optix {
#include <vector_types.h>
}

All CUDA types now reside in the optix:: namespace, which makes it impossible for Thrust to correctly reference these types. This does not get executed if <vector_types.h> is included somewhere before the OptiX header.

A similar issue occurs within optixu/optixu_vector_functions.h.

For now, I could either

  • add "using namespace optix;" whenever I include the OptiX header or
  • always make sure the correct order of includes.

I don’t really like both “solutions”, but would rather ask the OptiX developers not to change the CUDA types and functions.

Is this possible in the next release?

This is by design. If you want the cuda types to not be in the optix namespace you need to include the cuda headers before optix like you are doing. This was done to prevent collisions with other people’s float3 (and friends) types.

Is this documented somewhere? If not, a hint in the documentation might spare some headaches …

It was documented in one of the header files (optixpp.h), but it could certainly be more clear in the programming guide.