CUDA and C++ linking problems

Hi,

I’m developing a CUDA library with the biggest part written in C++. To test this library I have created a second project that uses this CUDA library. The library project compiles correctly, but as soon as I want to use it within the console test application I get a linker error that a function is not found.

I’m using Microsoft Visual C++ 2008 Express Edition with the CUDA Wizard installed.

The error:

error LNK2019: unresolved external symbol _smithwatermancuda referenced in function "public: void __thiscall SmithWatermanCUDA::run(void)" (?run@SmithWatermanCUDA@@QAEXXZ)

The library (so far) is basicly one class which calls a CUDA kernel from the run() function.

Some code snippets from the library project:

smithwaterman.cpp

#include "smithwatermancuda.h"

extern "C" void smithwatermancuda();

void SmithWatermanCUDA::run()

{

	smithwatermancuda();

}

smithwaterman.cu

#include "smithwatermancuda_kernel.cu"

extern "C" void smithwatermancuda()

{

	dim3 grid(1, 1, 1);

	dim3 threads(10, 1, 1);

	smithwatermancuda_kernel<<< grid, threads >>>();

}

smithwatermancuda_kernel.cu

#ifndef SMITHWATERMANCUDA_KERNEL_H

#define SMITHWATERMANCUDA_KERNEL_H

__global__ void smithwatermancuda_kernel()

{

}

#endif // SMITHWATERMANCUDA_KERNEL_H

So the library project builds correctly, but as soon as being used in a different application the linker error occurs.

I’ve attached the whole solution to this post.

Hopefuly somebody could explain what goes wrong.

Cheers,

Frank
CUDA_C___Test.rar (9.9 KB)

Ok, I managed to get it working.
It seems that smithwatermancuda.cu is never compiled by nvcc. If I rename it to something else, smithwatermancuda_test.cu it works fine. If this is a bug or if the filename (without extension) can’t be the same as a .cpp file I do not know.

So what I basically have is:
smithwaterman.h (class definition)
smithwaterman.cpp (class implemention)
smithwaterman.cu (external “C” function)
smithwaterman_kernel.cu (the actual cuda kernel)

the smithwaterman.cu didn’t get compiled, but after renaming it, it works fine.

Probably both smithwaterman.cu and smithwaterman.cpp were being compiled to smithwaterman.obj.