CUDA & the stl

Is it possible to use STL classes from host functions or to even #include an STL file in an nvcc-compiled source file?

The following cuda code generates all kinds of compiler errors:

#include <vector>

void test(void)






"C:\Program Files\Microsoft Visual Studio 8\VC\include\yvals.h", line 580: error: 

          identifier "__thiscall" is undefined

      explicit __thiscall _Lockit(); // set default lock


"C:\Program Files\Microsoft Visual Studio 8\VC\include\yvals.h", line 731: error: 

          member function with the same name as its class must be a constructor

      __thiscall _Mutex();

... etc

Encountered same problems here… does nvcc support generic programming? Also, when there was exception handling, nvcc thrown this error:

"C:\Program Files\Microsoft Visual Studio 8\VC\include\xlocale", line 369: error: 

          support for exception handling is disabled



As the manual says, nvopencc is a C compiler. C++ stuff like templates, exceptions, etc will not work.

However, as you can see with nvcc -v there is quite a bit of preprocessing going on using cl or gcc. So you can use C++ constructs that can be resolved all the way down to pure C functions in the preprocessing. An example is the functions templates used in the CUDA includes and SDK examples.


Dear Peter,

Does that mean generic class and exceptions won’t work at all?

Did the manual say that preprocessing is done by cudafe, not cl? BTW I have tried to switch it by -ncfe, but I didn’t help at all.

Or is there exists some “preprocessor” that can resolve all C++ constructs to C constructs?

Thank you very much.


The preprocessing uses both cl/gcc and cudafe. Do check whats going on with nvcc -v