C++ LNK2019 VS2012错误(未解析的外部符号)
我做了两个项目: 一个是提供者,我在里面添加了一个类DH:C++ LNK2019 VS2012错误(未解析的外部符号),c++,visual-studio-2012,linker,C++,Visual Studio 2012,Linker,我做了两个项目: 一个是提供者,我在里面添加了一个类DH: using namespace std; #ifdef PROVIDER_EXPORTS #define DH_API __declspec(dllexport) #else #define DH_API __declspec(dllimport) #endif #include <iostream> namespace Provider { class DH { public: s
using namespace std;
#ifdef PROVIDER_EXPORTS
#define DH_API __declspec(dllexport)
#else
#define DH_API __declspec(dllimport)
#endif
#include <iostream>
namespace Provider
{
class DH
{
public:
static DH_API std::string GetKey();
};
}
当我转储我得到的dll时:
?GetKey@DH@Provider@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ = @ILT+10(?GetKey@DH@Provider@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
关于一个新项目-测试仪
我包括dh.h
我已将提供程序项目的调试文件夹添加到链接目录中
我只是调用DH::GetKey
,但编译时我得到:
LNK2019: unresolved external symbol "__declspec(dllimport) public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl Provider::DH::GetKey(void)" (__imp_?GetKey@DH@Provider@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
LNK2019:未解析的外部符号“\uu declspec(dllimport)public:静态类std::basic\u string\uu cdecl Provider::DH::GetKey(void)”(\uu imp\ux?GetKey@DH@提供者@@SA?AV?$basic_string@DU?$char_traits@D@性病病毒$allocator@D@2@@std@@XZ)在函数“long\uu stdcall WndProc(struct HWND\uux*,unsigned int,unsigned int,long”中引用(?WndProc@@YGJPAUHWND)__@@IIJ@Z)
怎么了?您错过了导入的GetKey()函数。有一个项目引用部分,您应该添加定义该函数的项目。您需要设置项目依赖项或将dll的.lib文件添加到
测试仪的lib输入中,以便它知道在哪里搜索导入的函数。您是否设置了项目依赖项或添加了dll的.lib f我想问一下测试者项目?@spiritwolfform,请将此作为答案发布……我忘记了.lib
LNK2019: unresolved external symbol "__declspec(dllimport) public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl Provider::DH::GetKey(void)" (__imp_?GetKey@DH@Provider@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)