LNK2019 VS2012错误(未解析的外部符号)
LNK2019 VS2012 error (unresolved external symbol)
我做了2个项目:一个是提供者,我在里面添加了一个类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:
static DH_API std::string GetKey();
};
}
和小鬼:
#include "DH.h"
using namespace std;
namespace Provider
{
std::string DH::GetKey()
{
return "KEY";
}
}
当我转储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)
在一个新的项目上——测试者包括h。h我已经将Provider项目的调试文件夹添加到链接目录
然后调用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)
怎么了?
您需要设置项目依赖项或将dll的.lib文件添加到tester
项目的lib输入中,以便它知道在哪里搜索导入的函数
您错过了导入的GetKey()函数。这里有一个Project References部分,您应该添加定义该函数的项目。
相关文章:
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 未解析的外部符号_MsiLocateComponentW@12.
- 在C++中使用 gRPC 时未解析的外部符号
- LibPrivoxy: 未解析的外部符号 __declspec(dllimport) int __stdcall Sta
- 尝试从 XamlApplication 编译 C++/WinRT 空白应用程序时,我收到未解析的外部符号 winrt_make_*
- 我收到错误LNK2001:未解析的外部符号(C++代码)
- 可视抽象类 c++(错误 LNK 2001:未解析的外部符号)
- 如何摆脱C++中未解析的外部符号"private: static char"错误?
- 当 lib 已添加到其他依赖项时,如何在 VS 中调试未解析的外部符号错误
- 仅在少数方法(静态或共享库)中解析的外部符号
- 未解析的外部符号"__declspec(dllimport)与 Spdlog c++ 库
- 函数 _main (OPENGL C++) 中引用的未解析的外部符号 ________
- 错误LNK2019未解析的外部符号"public: __thiscall SLinkList<char>::SLinkList<char>(void)"
- 使用静态 constexpr 成员的未解析外部符号
- 引入参数化构造函数后显示 LNK 2019 未解析外部符号的代码错误
- Dlib LNK2001未解析的外部符号USER_ERROR__consistent_build_configurati
- 矛盾的未解决的外部符号+未使用的库与VS2017和FFMPEG 4
- 链接器错误:切换到unicode生成给出:未解析的外部符号WinMain
- 类模板上一个特定函数的未解析外部符号
- LNK2001:未解析的外部符号public:static类std::vector