CUDA static library link problem


I am having a problem about link a CUDA Static library with another console project.

First I create a static library which has the cuda code. Then I reference this static library with another concole poject.

But there is a link error, saying unresolved external symple “***”, which is the functionality written in cuda code.

I have no idea of how to solve it after many different trials.

Can anybody give me some clude? Thanks a lot

A common scenario where functions from CUDA code remain unresolved during linking is when CUDA code is called from plain C code. The CUDA compiler uses a C++ frontend, causing functions names to be decorated in the generated object code, whereas the object files for the calling C code contain the undecorated name (this is a generic issue in mixed C/C++ programming not specific to CUDA). To address this mismctahc one could compile the calling code as C++ code instead of C code, but more commonly one would instruct the CUDA compiler to leave the function name undecorated by use of an

extern "C"


Thanks, I already tried to add extern “C” in *.cu and it’s *.h; But it still shows as unresolved external symbol *.

Another information is I was using Visual Studio 2010 and CUDA 4.0 RC1.

you have to insert the extern “C” {foo(var1, var2…)} declerations both in the *.cu file and in the *.cpp file where you are calling the function.

also - make sure you’re NVCC compilation type is:“Generate hybrid object file (–compile / -c)”

good like,



I did try add extern “C” in various combination, It still doesn’t work.

The strange thing is I tried in VS2008 and CUDA 4.0 RC1, it works.

Is that possible is that because cuda4.0 RC1 doesn’t have good support in VS2010

I am using 64 bit environment

I list what I did, hope someone could help me out(Also, I attached the code). Currently I need to integrate a CUDA code library in to an existing codebase. I couldn’t move forward because of this. It is really driving me crazy…

  1. Console project

  2. Static library


    Inside this interface class, there is a interface function called CUDALIB::Interface(), It will call functionalities inside *.cu files.


    Inside, there is a simple function

    extern “C”

    void CUDAKernel()




  3. In CUDALIB::Interface()

    extern “C”

    void CUDAKernel();

    void CUDALIB::Interface()




The Link error is:

1>CUDALIB.obj : error LNK2019: unresolved external symbol CUDAKernel referenced in function “public: void __cdecl CUDALIB::Interface(void)” (?Interface@CUDALIB@@QEAAXXZ)

1>E:\Development\Test2010Cuda40\x64\Debug\Test.exe : fatal error LNK1120: 1 unresolved externals

The Compilation Line is

Compiling CUDA source file…

E:\Development\Test2010Cuda40\Test2010Cuda40>“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin\nvcc.exe” -gencode=arch=compute_10,code=sm_10 --use-local-env --cl-version 2010 -ccbin “C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\x86_amd64” -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include" -G0 --keep-dir “x64\Debug” -maxrregcount=32 --machine 64 -cuda -D_NEXUS_DEBUG -g -Xcompiler "/EHsc /nologo /Od /Zi /MDd " -o “x64\Debug\” “E:\Development\Test2010Cuda40\Test2010Cuda40\”
Test2010Cuda40.rar (1.54 MB)

hya again,

since I don’t have 4.0 installed, I could not open your project, BUT from your NVCC command line i believe as I suspected that you are not compiling into a hybrid object (–compile or -c). so what might be happening is that that you are compiling your CU file into a cubin and not linking your main to it.
Try selecting “generate hybrid object” in your “NVCC compilation type” field in the cuda build rule.
Alternatively you could explicitly link to the created cuda binary.


Thanks for the help. I couldn’t make it work.

Instead of using Static library, I change it to dll to achieve the goal. don’t know why 2010 doesn’t work with CUDA static library.