简体   繁体   中英

How to dll export a function template instantiation?

I have a template function with its definition defined in a header.h I want to export an instantiation of this function template. This is how I am trying to do so:

header.h

template<class T>
void my_function(T& x)
{
    // generic implementation with x
}

exports.h

#define DLL_EXPORT __declspec(dllexport)

exports.cpp

#include "exports.h"
#include "header.h"
template DLL_EXPORT void my_function(int& x);

Doesn't look like my DLL is exporting anything. Visual Studio says: "Function definition for "my_function" not found" in exports.cpp

Also, if I change the line in exports.cpp to:

template DLL_EXPORT void my_function<int>(int& x);

I'm also not able to get it to work!

Any ideas?

EDIT : Ok, false alarm. This does actually work. I was doing the dumpbin /exports my_dll.dll command on the wrong dll!!!

Ok, false alarm. This does actually work. I was doing the dumpbin /exports my_dll.dll command on the wrong dll!!!

It looks like you don't even need to explicitly write the template parameter out either - it'll be inferred.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM