CUDA and C++ C++ on .cu files - Tips on howto make it work

I am not sure if I did a right thing by starting a new topic. But then a forum search on “C++ support” returns nothing. Google seems to return better results than the forum search (nowadays after the new forum look n feel). Hence.

Also, I invite NVIDIA employees to post their suggestions as well.

When you include STL headers (like #include, #include etc.) on .cu files, you may get variety of compile errors, warnings and linker errors.

Here in, I am listing out a few things that I faced and how I solved them. Hopefully some1 finds this worthwhile.

Ever faced compilation problems like:
Error 1 internal error: assertion failed at: "D:/Bld/rel/gpgpu/toolkit/r2.0/compiler/edg/EDG_3.9/src/lower_name.c",
line 4179 C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE\xutility 870

This is a crazy error because the “D:/Bld…” directory never exists in first place. Compilation errors on non-existent files can piss any1 off.
This can be solved by installing VS 2005 SP1. The SP1 is freely downloadable. Just google it out.
The path has “…gpgpu/toolkit…” thing. How it is related to VS2005 SP1?? – I have no clue. Most likely that some NVCC problem is hiding there.

Thinking of it – The …gpgpu/toolkit… path actually stands for the source-file of the CUDAFE compiler itself. The guy who developed cudafe has stored the sources somewhere in D:/Bld… whatever. Hence.

But some how VS2005 SP1 does a magic there.

Facing linker errors that say "LNKxxxx: Symbol already defined…"?

When you use C++ constructs and STL in .cu files, you need to make sure that you pass proper “XCompiler” options to NVCC so that these options are passed to “cl”. The options that you should pass can be extracted from the project property pages corresponding to the build configuration (debug/release). Just copy,paste them (from the advanced-commandline section) and pass them to “Xcompiler” option of NVCC.

The only exception is “Dont pass the /TP or /TC” option. This is taken care by NVCC itself.

I still sometimes face the first problem at times when I write bad code (that anyway is not destined to compile).


I started a thread (with no replies so far) about the first problem you described:

I’ve installed SP1, but I still get the same problem. In my case, cudafe doesn’t like like functions returning templates. Cudafe doesn’t have anything against C++ code, as long as no complicated C++ libraries are used. I pass classes to functions in .cu files without a problem, but for example, when i try to use iostream, I get errors.

I this there is a problem with cudafe. I’ll report it as a CUDA problem.

I see… The forum search returned 0 results for my various searches… so, thats y, I started a new one.

This is sad. As I said, there is still some problem hiding. You may want to try adding the other VC options to NVCC (second issue) as well! I have seen that resolving compiling issues as well.

Good Luck!