Defining texture type in .cpp

Hi,

I defined the following texture variable

texture<float, 2, cudaReadModeElementType> tex;

, but I did it inside a .cpp, so it compiled with visual studio’s cl.exe. The compiler complained that it didn’t recognize the type, and a small check revealed that the texture template is defined in cuda_texture_types.h, but is restricted to nvcc by

#if defined(__cplusplus) && defined(__CUDACC__)

, due to the host prefix for the member functions.

I was wondering if there’s a good reason for this, or maybe I could mess around with it, and define this structure in a .h without the host prefix?

Textures must be defined in the same compilation unit as the device code which uses them. In CUDA device code, there is currently no concept of external linkage, so what you are trying to do cannot work.

Thanks