Integrate CUDA project with a C++ project

I have a Visual Studio C++ project, it uses a bunch of libraries, including boost, so nvcc can’t compile it.
Now I want to integrate several CUDA functions into it, but I’m not sure what the best way is.

I thought I would compile the CUDA project as a static library and then include it in the C++ project, but I get tons of warnings from the linker about redefined functions, like:

Warning	101	warning LNK4006: __lock already defined in MSVCRT.lib(MSVCR90.dll); second definition ignored	LIBCMT.lib

This results in this warning:

Warning	120	warning LNK4088: image being generated due to /FORCE option; image may not run	C:\..\...exe	1

Like it says, it doesn’t run.

Does anyone have exoerience with that kind of a setup?

One possible approach would be to isolate your cuda code into files with extension of .cu, and all your other host code (perhaps including boost) into .cpp files. You then create “wrapper” functions, which are defined in the .cu files, and callable from the .cpp files, to tie the pieces together. These wrapper functions can launch kernels or do other device-specific manipulation. You don’t need to create separate libraries to make this work.

There are a number of cuda samples which are organized this way, but the c++ integration sample should give you a framework including a VS project that you can start with:

http://docs.nvidia.com/cuda/cuda-samples/index.html#cpp-integration

Thank you, I will try it!

Edit: Ok, I tried it, and initially I had the same result (bunch of warning about wrong linking and the application didn’t start), but after setting the option “Runtime Library” to “Multi-Threaded DLL (/MDd)” the linking gave no extra warnings and my application runs fine so far.

I also tried my initial setup, and it also works now.

Maybe someone else gets some use out of that.