我有一个用 C++ 编写的 dll 和一个用 Visual C++ 编写的 exe。
我将 dll 中的函数声明为:
string __declspec( dllexport ) ConfigureHAT(T_STRING pathFile);
在 exe 项目中,我包含了所有的头文件和 dll 文件。
我调用dll中的函数:
string ret = ConfigureHAT("file.txt");
当编译可执行项目时,它失败并出现以下错误:
1>HATdllTester.obj : error LNK2028: unresolved token (0A000317) "class std::basic_string,class std::allocator > __cdecl ConfigureHAT(class std::basic_string,class std::allocator >)" (?ConfigureHAT@@$$FYA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z) referenced in function "private: void __clrcall HATdllTester::mainWindow::buttonConfigure_Click(class System::Object ^,class System::EventArgs ^)" (?buttonConfigure_Click@mainWindow@HATdllTester@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>AssemblyInfo.obj : error LNK2028: unresolved token (0A000316) "class std::basic_string,class std::allocator > __cdecl ConfigureHAT(class std::basic_string,class std::allocator >)" (?ConfigureHAT@@$$FYA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z) referenced in function "private: void __clrcall HATdllTester::mainWindow::buttonConfigure_Click(class System::Object ^,class System::EventArgs ^)" (?buttonConfigure_Click@mainWindow@HATdllTester@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>AssemblyInfo.obj : error LNK2019: unresolved external symbol "class std::basic_string,class std::allocator > __cdecl ConfigureHAT(class std::basic_string,class std::allocator >)" (?ConfigureHAT@@$$FYA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z) referenced in function "private: void __clrcall HATdllTester::mainWindow::buttonConfigure_Click(class System::Object ^,class System::EventArgs ^)" (?buttonConfigure_Click@mainWindow@HATdllTester@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>HATdllTester.obj : error LNK2001: unresolved external symbol "class std::basic_string,class std::allocator > __cdecl ConfigureHAT(class std::basic_string,class std::allocator >)" (?ConfigureHAT@@$$FYA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z)
有人能帮帮我吗? 我读了很多类似的错误相同的消息,但没有人解决我的问题。
谢谢。
编辑
最后,我把dll工程中生成的.lib文件放到Project Properties -> Linker -> Input -> Additional Dependencies中解决。
最佳答案
我会尝试更改 Visual Studio 项目配置。在 General > Common Language Runtime Support 下设置 /clr
而不是 /clr:pure
。
关于c++ - 由于 "Error LNK2028: unresolved token...",我无法编译解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19022481/