how solve [extern "C" template]?

I use template on runTest.cu file

[codebox]

template

void

runTest( int argc, char** argv)

{

}[/codebox]

and call this function at main.cpp file like this

[codebox]

extern “C” template void runTest(int argc, char** argv);

int main(int argc, char** argv){

runTest(argc, argv);

}

[/codebox]

but I get error “error C2894:”.

yes, I cannnot use [extern “C” tempalte].

but so how I call a tempate function on .cpp file? :wacko:

plz help!

This error can be caused by a template defined inside an extern “C” block.

http://msdn.microsoft.com/en-us/library/95bhc9c2.aspx

thanks tatou1234.

but I know it,nevertheless, I want to use template .cu function in .cpp file!

if anybody knows how use .cu template function in .cpp file, plz teach me!

Speaking about normal templates:

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().