CUDA 8.0 Visual Studio 2012 linker options when using Relocatable Device Code
<p>I have a class-based C++ code similar to <a href="https://devblogs.nvidia.com/parallelforall/separate-compilation-linking-cuda-device-code/" rel="nofollow noreferrer">this</a> and have followed the structure for declaring a <code>__device__</code> method of the class. I have also gone to <code>Project Properties-&gt; CUDA C/C++ -&gt; Common -&gt; Generate Relocatable Device Code</code> and changed it to YES but <a href="https://stackoverflow.com/questions/24459495/how-to-properly-link-cuda-header-file-with-device-functions">here</a> it says the linking options need modifying and I do not understand how to do this in the VS options from <a href="http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#examples" rel="nofollow noreferrer">this information</a>. How do I do this to get it to link?</p>

<p><em>**Removed VC studio settings in original post as not relevant**</em></p>

<p>Test code is:</p>

<p><strong>kernel.cu</strong></p>

<pre><code>#include "Test.cuh"

// CUDA kernel
__global__ void myKernel(Test* t) {

// Call device function
t-&gt;device_function();
}


// Entry point
int main()
{

// Create object (host and device copies)
Test* t = new Test();
Test* t_dev = NULL;
cudaMalloc(&amp;t_dev, sizeof(Test));

// Copy object
cudaMemcpy(t_dev,t,sizeof(Test),cudaMemcpyHostToDevice);

// Call kernel passing pointer to device copy of the object
myKernel&lt;&lt;&lt;1,1&gt;&gt;&gt;(t_dev);

}
</code></pre>

<p><strong>Test.cuh</strong></p>

<pre><code>class Test
{
public:
Test(void);
~Test(void);

__device__ void device_function();
};
</code></pre>

<p><strong>Test.cu</strong></p>

<pre><code>#include "Test.cuh"
Test::Test(void){}
Test::~Test(void){}

__device__ void Test::device_function() {

// Do something

}
</code></pre>

<p><strong>EDIT</strong></p>

<p>Adding compilation log as I think it might not be compiling the device implementation properly.</p>

<pre><code>1&gt; C:\C++ Projects\CudaTest\CudaTest&gt;"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin\nvcc.exe" -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin"  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include"     --keep-dir Release -maxrregcount=0  --machine 32 --compile      -DWIN32 -DNDEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /O2 /Zi  /MD " -o Release\kernel.cu.obj "C:\C++ Projects\CudaTest\CudaTest\kernel.cu" -clean
1&gt;  kernel.cu
1&gt;  Compiling CUDA source file kernel.cu...
1&gt;  
1&gt;  C:\C++ Projects\CudaTest\CudaTest&gt;"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin\nvcc.exe" -gencode=arch=compute_20,code=\"sm_20,compute_20\" --use-local-env --cl-version 2012 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin" -rdc=true -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include"     --keep-dir Release -maxrregcount=0  --machine 32 --compile -cudart static     -DWIN32 -DNDEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /O2 /Zi  /MD " -o Release\kernel.cu.obj "C:\C++ Projects\CudaTest\CudaTest\kernel.cu" 
1&gt;  kernel.cu
1&gt;  Test.cu
1&gt;  
1&gt;  C:\C++ Projects\CudaTest\CudaTest&gt;"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin\nvcc.exe" -dlink -o Release\CudaTest.device-link.obj -Xcompiler "/EHsc /W3 /nologo /O2 /Zi  /MD " -L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\Win32" cudart.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  -gencode=arch=compute_20,code=sm_20  --machine 32 Release\kernel.cu.obj 
1&gt; CUDALINK : nvlink error : Undefined reference to '_ZN4Test15device_functionEv' in 'Release/kernel.cu.obj'`
</code></pre>