XP + vs2005 + CMake + .lib => linking problem

Hi, Here is my problem, I try to create a static lib in one of my VS projects :

+ RSolution

|--+ RCuda => Static .lib

    | -- RCUTest.h

    | -- RCUTest.cu

|--+ RApp => .exe linking RCuda

    | -- main.cpp

My Cuda code is Really simple :


extern "C" void runTestCuda();


#include "RCUTest.h"

extern "C" void runTestCuda() {};


int main (int argc, char **argv)


Here are the CMake command lines (.lib):




(.exe) :

ADD_EXECUTABLE( RApp main.cpp)


Building&linking RCuda works fine, but when linking RApp, I get the following error message :

main.obj : error LNK2019: symbole externe non résolu _runTestCuda référencé dans la fonction ...

In English it is something like : error LNK2019: unresolved external symbol _runTestCuda referenced in function …

I’ve opened the generated file RCuda.lib, and it contains _runTestCuda

I’ve checked RCuda.lib is well included in RApp generation command line.

I’m becoming mad … <img src=‘http://hqnveipbwb20/public/style_emoticons/<#EMO_DIR#>/crying.gif’ class=‘bbc_emoticon’ alt=’:’(’ />

A big big thank to the one who solves the problem.

How about your compile command?

BTW, you can have a try with my wizard to create lib file~ you can download from here:

I’ve tried your Wizard, and it work’s fine for a simple application, the problem is that I have to use CMake to manage my app, as the code I write is integrated in a huge CMake project with lots of .lib and dependencies, maybe if we find what’s wrong in compiler’s arguments, I’ll be able to modify CMake script to make solve the problem.

Here are the command line arguments for C++ compiler :

/O2 /Ob2 /I "F:\Dev\Projects008_RTools\trunk\src" 


/D "CMAKE_INTDIR=\"Release\"" /D "_MBCS" 

/FD /EHsc /MD /Fo"RApp.dir\Release\" 


/W3 /nologo /c /TP /errorReport:prompt

And for the linker :









/PDB:"F:/Dev/Projects/2008_RTools/trunk/bin/Release\RApp.pdb" /SUBSYSTEM:CONSOLE /STACK:10000000


kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib cuda.lib cudart.lib RCuda.lib


Is this CUDA 1.1 or 2.0 beta that you are using?

I find that in CUDA 1.1 I need to change the “SET(generated_file …” line in FindCuda.cmake to generate a file with a .c extension. In CUDA 2.0 it only works if the extension is .cc. I can’t explain why this happens, but it does.

Delete the extern “C”. And then it works.

And delete the include headfile from the RCUTest.cu.

  1. (extern “C”) is not a symbol in the C program.
  2. (extern “C”) in the head file is can’t work for the CPP file. The lib can be created if there is no (extern “C”) in the CPP file & (extern “C”) in the head file.
    3.(.exe) :use main.cpp file makes the compiler ignored the 1 error.

Thanks I’ve made the change an it solved another problem.

Very big thank you, I still have trouble to understand how extern “C” works, but I solved my problem using the following lines :

#ifdef __cplusplus

extern "C" 


void runTestCuda();

I’m not sure it’s the best way to do it, but for me it worked, I’ll go back to explanations on extern “C” one day to really understand how it works.

Yes, it’s the best.

Then the headfile can support CPP & C both.