How to reuse kernels in multiple files (for unit testing) Without getting multiply defined linking e

How can I go about reusing the same kernel without getting fatal linking errors due to defining the symbol multiple times

In Visual Studio I get

“fatal error LNK1169: one or more multiply defined symbols found”

My current structure is as follows:
Interface.h has an extern interface to a C function: myCfunction() (ala the C++ integration SDK example) contains the actual global functions and is NOT included in the build: my_kernel() inlcudes and Interface.h and calls my_kernel<<<…>>>

This all works fine.

But if I add another C function in another file which also includes and uses those kernels, I get the errors.

So how can I reuse the kernels in among many C functions in different files.

The purpose of this by the way is unit testing, and integrating my kernels with CPP unit, if there is no way to reuse kernels (there must be!) then other suggestions for unit testing kernels within my existing CPP unit framework would be appreciate.



I do it like this:

  __global__ void MyFunctionKernel() {

	// kernel code


void CallMyFunctionKernel() {




  extern void CallMyFunctionKernel();

Just link it in with your program. Whenever you want to run kernel from your C++ app, just include MyFunction.h and call the CallMyFunctionKernel function.