CUDA static library not linking in VS2013 project.


I’m trying to create some static libraries to be used in a CUDA program, however I am getting a compiler error MSB3721L… exited with code 255. More specifically, here is the error:

[b]1>C:\Users\User\Documents\Visual Studio 2013\Projects\Test CUDA App\Test CUDA App>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\bin\nvcc.exe" -dlink -o "x64\Debug\Test CUDA App.device-link.obj" -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd " -L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\lib\x64" -L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\lib\x64" -LD:\Libs D:\Libs\deviceLib.lib 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_30,code=sm_30 -G --machine 64 x64\Debug\ 
1>CUDALINK : nvlink error : Undefined reference to '_Z16devFunctionff' in 'x64/Debug/'[/b]

The codes are very simple, and copy/pasted form supposedly working examples I found online. Here are the two files that I use for creating the static library:


#ifdef __CUDACC__
#define CUDADEV __host__ __device__
#define CUDADEV

extern CUDADEV float devFunction(float a, float b);

#include "deviceLib.h"

CUDADEV float devFunction(float a, float b) {
	return a + b;

This compiles fine, and creates the deviceLib.lib file. In a completely separate CUDA application, I have the following:

#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include "deviceLib.h"

__global__ void simpleAdd(float a, float b, float * target)
	*target = devFunction(a, b);

int main()
	float hostTarget;
	float * devTarget;
	cudaMalloc((void**)&devTarget, sizeof(float));
	simpleAdd << < 1, 1 >> > (5, 5, devTarget);

	cudaMemcpy(&hostTarget, devTarget, sizeof(float), cudaMemcpyDeviceToHost);
	return 0;

For which the .lib file is in, inside of the project configuration properties, I have added the directory for the VC++ Directories, added it to the Linker->Input->Addition Dependencies, Generated Relocatable Device Code = True, Perform Device Link = Yes.

What am I missing to get this CUDA application linked to the deviceLib? IntelliSense also picks up on it. Thanks in advance.

Looks like it compiles fine for me when I replaced the original sample codes in CUDA Samples - "simpleSeparateCompilation " with your above codes.

C:\ProgramData\NVIDIA Corporation\CUDA Samples\v7.5\0_Simple\simpleSeparateCompilation