CUDA does not seem to call native compiler Linker errors with C++ class


from what I understand regarding the CUDA compile chain, the front-end (cudafe) is supposed to separate host from device code that is encoded into a single .cu file. To digg down some linker errors I was getting, I took a pure .cpp file (no CUDA code inside) with implementations of class methods, renamed that file to *.cu and added the following custom build step to it in Visual Studio:

"$(CUDA_BIN_PATH)\nvcc.exe" -ccbin "$(VCInstallDir)bin" -c -D_DEBUG -DWIN32 -D_CONSOLE -D_MBCS -Xcompiler /EHsc,/W3,/nologo,/Wp64,/Od,/Zi,/RTC1,/MTd -I"$(CUDA_INC_PATH)" -I./ -I../../common/inc -I"$(DXSDK_DIR)\Include" -Xcudafe --diag_suppress=unsigned_compare_with_negative -o $(ConfigurationName)\$(InputName).obj $(InputName).cu

with “Outputs” set to


When I compile and link this file, I get linker errors because none of the C++ class methods implemented in that file are found. It seems cudafe does not correctly pass the code to cl.exe to compile the C++ code. What am I missing here?


I just investigated the OBJ file created by the custom build step. The file contains the C++ method names, but with a different name mangling as expected by the VS linker. It seems the C++ does not get compiled by VS after all …

EDIT: I’m getting the impression that it’s not possible to call global functions from C++ code, only from C code, it that possible?

This really seems to be the case, see Mark’s comment here. I’ve now switched to using cudaLaunch() which seems to work fine.