我有一个用 C++ 编写的 dll 和一个用 Visual C++ 编写的 exe。
我将 dll 中的函数声明为:
string __declspec( dllexport ) ConfigureHAT(T_STRING pathFile);
在 exe 项目中,我包含所有头文件和 dll 文件。
我在dll中调用该函数:
string ret = ConfigureHAT("file.txt");
当编译可执行项目时,它会失败并出现以下错误:
1>HATdllTester.obj:错误LNK2028:无法解析的令牌(0A000317)“类
std::basic_string,类
std::allocator > __cdeclConfigureHAT(类
std::basic_string,类
std::分配器>)"
(?配置HAT@@$$FYA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z)
在函数“private: void __clrcall”中引用
HATdllTester::mainWindow::buttonConfigure_Click(类 System::Object
^,类 System::EventArgs ^)"
(?buttonConfigure_Click@mainWindow@HATdllTester@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>AssemblyInfo.obj:错误 LNK2028:无法解析的标记(0A000316)“类
std::basic_string,类
std::allocator > __cdeclConfigureHAT(类
std::basic_string,类
std::分配器>)"
(?配置HAT@@$$FYA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z)
在函数“private: void __clrcall”中引用
HATdllTester::mainWindow::buttonConfigure_Click(类 System::Object
^,类 System::EventArgs ^)"
(?buttonConfigure_Click@mainWindow@HATdllTester@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>AssemblyInfo.obj:错误LNK2019:无法解析的外部符号“类
std::basic_string,类
std::allocator > __cdeclConfigureHAT(类
std::basic_string,类
std::分配器>)"
(?配置HAT@@$$FYA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z)
在函数“private: void __clrcall”中引用
HATdllTester::mainWindow::buttonConfigure_Click(类 System::Object
^,类 System::EventArgs ^)"
(?buttonConfigure_Click@mainWindow@HATdllTester@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>HATdllTester.obj:错误 LNK2001:无法解析的外部符号“类
std::basic_string,类
std::allocator > __cdeclConfigureHAT(类
std::basic_string,类
std::分配器>)"
(?配置HAT@@$$FYA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z)
有谁能够帮助我?
我读了很多类似的消息,都有同样的错误,但没有人解决我的问题。
Thanks.
EDIT
最后,我解决了将dll项目中生成的.lib文件放入项目属性->链接器->输入->附加依赖项中的问题。
我会尝试更改 Visual Studio 项目配置。在“常规”>“公共语言运行时支持”集下/clr
代替/clr:pure
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)