Can the CUDA grogramming with C++?

I want to grogram a CUDA code to execute on my GPU(en8800 GTX).

Within the code , I may have included CUDA’s .cu file and C++'s .cpp file.

but i don’t know whether the .cu file can doing with C++ file (ex: with class

type, and any class styles).

Sorry ENGLISH isn’t my national language. grammar may be wrong , please forgive it.

Hi Mimichw -

Some C++ seems to work in CUDA, but I don’t believe it is officially supported, and some things do not work. Many simple things, such as overloaded operators, and inline constructors, etc… work. Anything that cannot be inlined will not work.


You can call host functions in your .cu file from functions in your .cpp file.

Declare the .cu function extern “C” , and in the .cpp file, include a prototype, also with extern “C”. (At least, I have to do this under Visual Studio to prevent name mangling.)


// in .cu file

extern "C" bool runKernel(float param) {

// code here



// in .cpp file: prototype

extern "C" bool runKernel(float param);

I’ve appreciated your reply.

I have known how to use a function in .cpp with .cu.

Then, i try it today, i create my new class in the .cpp, (user defined type) and to

do some work to get some useful values into the class data menbers.

but I have a question now. How can i use this data in the data menbers within .cu?

I don’t think nacc compiler always accept this. :(