问题是我的编译器无法从dll文件解析函数
这是我的图书馆代码
#ifndef DLL_SAMPLE
#define DLL_SAMPLE
#include <iostream>
class A
{
public:
static void a();
};
#endif
#include "DllSample.h"
void A::a()
{
std::cout << "hello, world" << std::endl;
}
我的源代码
#include "DllSample.h"
int main(int argc, char* argv[])
{
A::a();
return 0;
}
如果我将函数内联到头文件中,它将起作用,但是当我这样做时,上面的构建将失败。
消息是:
1> main.obj : error LNK2019: unresolved external symbol "public: static void __cdecl A::a(void)" (?a@A@@SAXXZ) referenced in function _main
1> D:\Home\Document\Visual Studio 2019 Projects\ErrorShot\Debug\CallDllFunctionSample.exe : fatal error LNK1120: 1 unresolved externals
1> The command exited with code 1120.
1> Done executing task "Link" -- FAILED.
1>Done building target "Link" in project "CallDllFunctionSample.vcxproj" -- FAILED.
1>
1>Done building project "CallDllFunctionSample.vcxproj" -- FAILED.
1>
1>Build FAILED.
1>
1>main.obj : error LNK2019: unresolved external symbol "public: static void __cdecl A::a(void)" (?a@A@@SAXXZ) referenced in function _main
1>D:\Home\Document\Visual Studio 2019 Projects\ErrorShot\Debug\CallDllFunctionSample.exe : fatal error LNK1120: 1 unresolved externals
1> 0 Warning(s)
1> 2 Error(s)