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 :

RCUTest.h

extern "C" void runTestCuda();

RCUTest.cu

#include "RCUTest.h"

extern "C" void runTestCuda() {};

main.cpp

int main (int argc, char **argv)

{runTestCuda();}

Here are the CMake command lines (.lib):

CUDA_INCLUDE_DIRECTORIES(  ${CMAKE_CURRENT_SOURCE_DIR})

CUDA_INCLUDE_DIRECTORIES( ${CUDA_CUT_INCLUDE} )

CUDA_ADD_LIBRARY(RCuda RCUTest.cu RCUTest.h)

(.exe) :

ADD_EXECUTABLE( RApp main.cpp)

TARGET_LINK_LIBRARIES(RApp RCuda)

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:
http://forums.nvidia.com/index.php?showtopic=69183

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 "WIN32" /D "_WINDOWS" /D "NDEBUG" /D "QT_NO_DEBUG"

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

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

/Fd"F:/Dev/Projects/2008_RTools/trunk/bin/Release/RApp.pdb" 

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

And for the linker :

/OUT:"F:\Dev\Projects008_RTools\trunk\bin\Release\RApp.exe" 

/VERSION:0.0 /INCREMENTAL:NO /NOLOGO 

/LIBPATH:"..\..\..\bin\Release" 

/LIBPATH:"..\..\..\bin" 

/LIBPATH:"C:\CUDA\lib\Release" 

/LIBPATH:"C:\CUDA\lib" 

/MANIFEST 

/MANIFESTFILE:"RApp.dir\Release\RApp.exe.intermediate.manifest" 

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

/ERRORREPORT:PROMPT 

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

Thank’s

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" 

#endif

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.