You're exporting a class member function void MyFuncLibInterface::myFunc(std::string param);
but trying to import a free function void myFunc(std::string param);
Make sure you #define MyFuncLib_EXPORTS
in the DLL project. Make sure you #include "MyFuncLibInterface.h"
in the console app without defining MyFuncLib_EXPORTS
.
The DLL project will see:
class __declspec(dllexport) MyFuncLibInterface {
...
}:
And the console project will see:
class __declspec(dllimport) MyFuncLibInterface {
...
}:
This allows your console project to use the class from the dll.
EDIT: In response to comment
#ifndef FooH
#define FooH
#ifdef BUILDING_THE_DLL
#define EXPORTED __declspec(dllexport)
#else
#define EXPORTED __declspec(dllimport)
#endif
class EXPORTED Foo {
public:
void bar();
};
#endif
In the project which actually implements Foo::bar()
BUILDING_THE_DLL
must be defined. In the project which tries to use Foo
, BUILDING_THE_DLL
should not be defined. Both projects must #include "Foo.h"
, but only the DLL project should contain "Foo.cpp"
When you then build the DLL, the class Foo and all its members are marked as "exported from this DLL". When you build any other project, the class Foo and all its members are marked as "imported from a DLL"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…