I have a template function in a shared library. I know the function will be called with either int or double arguments. I therefore instantiate the two versions of the template in the source file.
template void library::doSomething<int>(int const number);
template void library::doSomething<double>(double const number);
This solution works with g++ on Linux (getting a *.so), but when I try to compile the same code into a *.dll on Windows using VS2010 I get an error like this:
error LNK2001: unresolved external symbol doSomething
Exports are provided in a *.def file like:
EXPORTS
doSomething
Am I missing something or is this solution “incompatible” with Windows?
Thanks.
Petr
You need to put the mangled names of the instantiated functions into the DEF file, not the C++ names.
You can find out more in the MSDN article Exporting from a DLL Using DEF Files:
Usually, using
__declspec(dllexport)is much more straightforward and if you can use it you should consider doing so.