C++ name mangling

When using Linux/GCC I note that my C++ code can call out to my cuda files, and vice versa. The CUDA compiler uses the same name mangling as GCC on the C++ symbols, and everything works great.

When I use Visual Studio (2003) this no longer works. I need to make sure that any calls back and forth between my normal .cpp files and my .cu files go via ‘extern “C”’ functions.

Is there a way to control the name mangling that the CUDA compiler uses so that I don’t need to go via ‘extern “C”’ functions?

I tried setting the ‘–no-cpp-cudafe’ option, but this generated hundreds of errors coming from the system header files; so I gave up on this option.

Thanks in advance,
Paul Richards

extern “C” is the normal way of controlling the name mangling. Is it really that much effort to put extern “C” { at the top of every header file and } at the bottom?

I cannot use the ‘extern “C”’ trick to make a C++ function easy to call from my .cu files.

I instead need to wrap the C++ function I want to call with a small ‘extern “C”’ “trampoline” function, then invoke the trampoline function from my .cu file. This is the process I’d like to eliminate.

Using ‘extern “C”’ is only applicable when invoking .cu functions from C++, not the other way around…

Sorry, I missed that this was your intention from the first post. I can’t help you then since I have designed my code with only one way calls C++ -> cu and have never tried going the other way.

Yep, I have come to the conclusion that I simply need to move this code out from my .cu file. There is nothing stopping me from moving it into its own cpp file.