M$ Visual Studio setup for CUDA How to set up the configuration for M$VS

I am using Microsoft Visual Studio 2005 (version 8) and would like to set up the necessary includes and libraries in order to be able to compile, for instance, one of the Nvidia examples. So far I have solved several issues:

  • First of all I have set the Custom Build Rules provided by JaredHoberock.
  • Then I added CUDA\include and CUDA\lib directories in the Options menu.
  • Next thing, I added the Additional Dependences in the Project Properties menu (cuda.lib, cudart.lib, … and so on).
  • And finally, I solved a library conflict by ignoring LIBCMTD.lib.

As far as I understand, this should do the job, but I still get a link error. I get several unresolved external symbol errors according for every call I do from a .cpp file to a .cu file. It seems like it only tries to link the .cpp files ignoring the .obj compiled .cu files.
I have tried to fix the problem in many different ways but I don’t seem to have any success.
I imagine it can be just a simple modification, but I have no idea which one. Could someone please point me out how to fix the linking problem?

Have you declared the functions in the .cu file ‘extern “C”’? Failing to do that would lead to unresolved symbols because c++ and C mangle names differently.

Cool!!! :yes: This is exactly what I was looking for. Now it works perfectly.
However, I can’t make those functions inline, so I have another question now. Does someone know how to make an extern “c” host void function() inline? Do I have to put it only in the .cu file? :huh:

You should use extern “C” functions as a border between C++/C code compiled by your normal compiler and CUDA. Inline’ing an extern function doesnt make sense since extern function definition will not be available until some other library/file is linked.

You can use the same functions in CUDA and C/C++ but then you have to include the function definition for both compilers.
you can use includes like :

#include <vector_types.h>
#include <cutil.h>

To have access to cuda specific types or methods.

You can hide parts of the code from specific compilers using default preprocessor definitions

#ifdef CUDACC

CUDACC will be defined when CUDA compiler is used.