VS2005 CUDA Build Error Trouble building solution

Hi Everyone,

I’ve been trying to start a new CUDA project in VS2005, and I have a weird error. I have my SGM_main.cu file, my SGM_kernel.cu file, and a SGM_host.cpp file. The SGM_main.cu file only has the main method and calls only cutil for CUT_DEVICE_INIT() and CUT_EXIT() (this is just a little test file to make sure the project can compile. SGM_main.cu also has: “#include<SGM_kernel.cu>” and the first time I build the project, everything runs fine. However after changing something in main.cu, and rebuilding, I get the following error:

1>SGM_main.obj : error LNK2005: __device_stub__Z10SGM_kernelPfS already defined in SGM_kernel.obj
1>F:\SGM_CUDA\Release\SGM_CUDA.exe : fatal error LNK1169: one or more multiply defined symbols found
1>Build log was saved at “file://f:\SGM_CUDA\Release\BuildLog.htm”
1>SGM_CUDA - 2 error(s), 0 warning(s)

SGM_kernel.cu has:
global void SGM_kernel() {}

When I change SGM_kernel to some other name, and rebuild, it works. The second time I rebuild again however, it gives that same LNK2005 error. This is so weird and annoying- can someone please help? Thanks!



There is nothing pbm with your code.Just right click the SGM_kernel.cu program,there you able to find properties in that just remove the contents in each command line,output,add. depend. in (custom build rule->general).

I ran into the same problem. The previous post was helpful, but a bit vague so I have documented my experience here. In my case, I was sourcing and separately compiling the device function (the GPU kernel code). I used #include in my main app to pull in and reference the device function. When the main app is compiled, the included device function is also compiled. Separate to this, the original .cu file that has the device function definition is also compiled as this is the default behavior with the CUDA custom build rule for VS2005. At link time there are two compilations of the same source, resulting in a symbol conflict.

There are a number of ways to avoid this. The simplest is to exclude the device function .(cu file) from being compiled. You can do this as follows:

  1. Select the source file (.cu) with the device function in the VS Solution Explorer window

  2. View the file properties (right mouse click over the object)

  3. Select Configuration Properties > General in the left pane

  4. Set “Exclude From Build” to “yes” on the right pane

  5. Select “ok”

You will now see a red stop sign icon for the device function .cu file in the Solution Explorer. A rebuild should resolve the conflict.