The entire template definition needs to be available in a header file so that the compiler can instantiate it when the code using the template is called. More specifically to your problem: you cannot possibly have extern “C” template, because extern “C” removes the name mangling and that name mangling is needed to separate the templates from one another! Even if you could get it to compile, you’d have multiply defined runTest functions with no way to tell which is which!
The header file thing won’t work with nvcc, because obivisouly if you put a kernel<<<>>> call in a header and try and call it from the cpp file = compilation error.
The only solution I see is for you to know a priori the types T that will be used and instantiate those main functions in the .cu file
// in header file
extern "C" void runTest_int(int argc, char**argv);
extern "C" void runTest_float(int argc, char**argv);
extern "C" void runTest_double(int argc, char**argv);
template<class T> void runTest( int argc, char** argv)
{
...
}
void runTest_int(int argc, char**argv)
{
runTest<int>(argc, argv);
}
... you get the idea
Then you simply call runTest_int() from the cpp file instead of runTest().