Creating a cuda .lib How do I make a stand alone lib?

Hi,

I am trying to create a small .lib file which contains a cuda function (eg RunTest) which can be linked in by an existing application. (vc7)

The problem is, RunTest ( which is in a .cu file ) somehow does not get exported into the lib. <img src=‘http://hqnveipbwb20/public/style_emoticons/<#EMO_DIR#>/crying.gif’ class=‘bbc_emoticon’ alt=’:’(’ />

Ie My app links in mytest.lib, however it cannot find RunTest within it.

In my lib project, I can define other functions in seperate cpp files and they are exported correctly - however .cu functions not. Any ideas? :unsure:

Thanks

Try wrapping the functions you want to export with

extern "C" { }

Mark

Hi Mark, unfortunately I have tried this, still no joy… :(

Tried variations of extern “c” in both the lib and calling program - Still can not bind either way

In lib:

extern “C” {
////////////////////////////////////////////////////////////////////////////////
//! Run a simple test for CUDA
////////////////////////////////////////////////////////////////////////////////
void runTest( int argc, char** argv)
{
CUT_CHECK_DEVICE();
… etc …

In calling program:
extern “C”
{ void runTest( int argc, char** argv); };
int main(int argc, char** argv)
{
runTest( argc, argv);
return 0;
}

error LNK2019: unresolved external symbol _runTest referenced in function _main

(Although other cpp functions defined in this lib work fine)

… has anyone been able to make it cuda work as a library, either as a lib or dll?

Can only assume function name mangling works differently with nvcc than visual c++?

I’ve had to do this a few times to link things properly. Why is it necessary?

To support function overloading (same name, but different argument number/types), C++ compilers often pad the name of the function in a library with extra characters to represent the argument types. That way it can tell foo(int a) from foo(double a) when linking to a library. (The results look kind of ugly, turning foo into __foo_i, so this feature is called “name mangling.”)

Putting ‘extern “C”’ around your declaration tells the compiler than name mangling should not be applied to this function, so it will just look for the unmodified name. This often is necessary when linking code compiled with C++ and some other compiler that follows the C convention (no mangling).

Why is name mangling disabled for CUDA host functions? Is this an option passed to the c++ compiler?

Hi, MikeCuda, I have exactly the same problem as yours :

Did you find a way to solve the problem ? (I hope for you, as your post is one year old :) )

Thank’s

Problem solved here :

http://forums.nvidia.com/index.php?showtopic=70556