dll export header
extern "C"
void _declspec(dllexport) __stdcall foo();
.def file
EXPORTS
foo @1
When I build the dll by 64bit build config, I meet this warning.
warning LNK4197: export 'foo' specified multiple times; using first specification
But If I build the dll by 32bit build config, the warning never occurs.
What is the problem? What is the difference.
In dll header for interface, we usually use this technic,
#ifdef EXPORT_DLL
#define BASICAPI _declspec(dllexport)
#else
#define BASICAPI _declspec(dllimport)
#endif //_EXPORT_DLL
But if def file also exists, we always will be meet the warning when we are building 64bit dll.
So, should we write the codes like this?
#ifdef EXPORT_DLL
#define BASICAPI
#else
#define BASICAPI _declspec(dllimport)
#endif //_EXPORT_DLL
It works well. But it's not familiar to me.
Give me any your opinions.
It's generally not good practise to specify exports twice for the same function. If you already have __declspec(dllexport)
then you do not need to specify the export in a .def file as well. Conversely, if you have the export listed in a .def file, then there's no need for a __declspec(dllexport)
.
I believe the reason for the warning is that in x86 builds, the __declspec(dllexport)
is exporting the decorated name with a leading underscore, but the 64-bit compiler does not decorate names with a leading underscore, leading to the duplicate. To verify this, you could look at the 32-bit DLL in Dependency Walker and you should see two exported functions, "foo" and "_foo".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With