LNK2019 VS2012错误(未解析的外部符号)

时间:2013-06-19 09:44:11

标签: 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:
        static DH_API std::string GetKey();
    };
}

和Imp:

#include "DH.h"

using namespace std;
namespace Provider
{


    std::string DH::GetKey()
    {

        return "KEY";
    }

}

当我把dbin转储到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 我已将Provider项目的debug文件夹添加到链接目录

我只是打电话给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)

有什么问题?

2 个答案:

答案 0 :(得分:1)

您需要设置项目依赖项或将您的dll的.lib文件添加到tester项目的lib输入中,以便它知道在哪里搜索导入的函数

答案 1 :(得分:0)

您错过了导入的GetKey()函数。有一个Project References部分,您应该添加定义该功能的项目。

相关问题