Reputation: 181
It would appear that the example couldn't get any simpler:
//Example.h
#pragma once
#ifdef EXPORTING_DLL
extern __declspec(dllexport) void HelloWorld();
#else
extern __declspec(dllimport) void HelloWorld();
#endif
//Example.cpp
#include "Functions.h"
#define EXPORTING_DLL
void HelloWorld()
{
}
So, what I have problems with? OK, when trying to compile as it is, that is after creation of dll type project in VS, I'm getting warning:
warning C4273: 'HelloWorld': inconsistent dll linkage
if I change definition of HelloWorld in cpp file to:
__declspec(dllimport) void HelloWorld()
{
}
I'm getting error:
Error C2491 'HelloWorld': definition of dllimport function not allowed
If on the other hand I change definition of HelloWorld to:
__declspec(dllexport) void HelloWorld()
{
}
I'm getting warning:
Warning C4273 'HelloWorld': inconsistent dll linkage
Any idea how to define it so it compiles without any warnings? I mean, those warnings are at least worrying.
Upvotes: 0
Views: 3931
Reputation: 9852
You need to define EXPORTING_DLL
before you include the header. That way the header can declare the correct prototype based on whether you are importing or exporting.
Without doing this it will import which is not what you want
Upvotes: 1