syntax-error - 使用库时未解析的外部符号

标签 syntax-error linker-errors

我有一个名为NetworkInterfaceInfoProvider.h的头文件。
在此头文件中,我声明一个类,如下所示:

#ifndef INETWORK_INTERFACE_INFO_PROVIDER_H
#define INETWORK_INTERFACE_INFO_PROVIDER_H
#pragma once
/*#include "stdafx.h"*/
#include "IConfig.h"
#include "NetworkAddapterAddresses.h"
#include "InstaledAddapters.h"

namespace IRNetwork
{
    class CLASS_DECLSPEC INet;
    struct CLASS_DECLSPEC GenericIPAddress;
    /*
    * provide information about all network interface related adapters such as installed interfaces , addresses , best routes and ...
    * TO DO: implement Other OS's
    */
    class CLASS_DECLSPEC INetworkInterfaceInfoProvider
    {
    public:
        INetworkInterfaceInfoProvider(void);
        ~INetworkInterfaceInfoProvider(void);

        int32_t GetBestRouteTo(char* destIp,uint16_t port,ip_t *ip);
        int32_t GetBestRouteTo(GenericIPAddress* ip);
    private:
        INet* snet;
    };
}
#endif

当我想在控制台应用程序中使用它时,出现以下链接器错误

* 注意:上面的代码库已链接到我的控制台应用程序。
CLASS_DECLSPEC是dll导入/导出定义*


error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall IRNetwork::INetworkInterfaceInfoProvider::GetBestRouteTo(char ,unsigned short,char ()[65])" (_imp?GetBestRouteTo@INetworkInterfaceInfoProvider@IRNetwork@@QAEHPADGPAY0EB@D@Z) referenced in function "void __cdecl test_adapters(void)" (?test_adapters@@YAXXZ) testDhcpv4.obj testDhcpv4



这是怎么了

最佳答案

嗯从错误我会说导入看起来不错。因此,也许在导出时出错。假设您使用的是Visual Studio,则可以使用dumpbin来检查dll是否正确导出:

打开“Visual Studio命令提示符”(可从Windows“开始”菜单中获得)并键入

dumpbin /EXPORTS yourlib.dll

然后,您应该看到我们的导出,类似于(从我的一个dll中转储):
...
170   A9 00108120 ??1AbstractParam@param@core@megamol@@UAE@XZ = ??1BoolParam@param@core@megamol@@UAE@XZ (public: virtual __thiscall megamol::core::param::BoolParam::~BoolParam(void))
...

如果未列出您正在调用的函数,则应在构建dll时再次检查dllexport是否设置正确。

如果列出了该函数,但外观不同,则应检查应用程序和dll的调用约定是否相同。

如果列出了该函数,并且名称与错误消息中的名称相同,请仔细检查是否正确链接了dll的导入库。

另外,请检查您的应用程序和dll的运行时配置是否相同(例如,多线程DLL或多线程调试DLL)。

关于syntax-error - 使用库时未解析的外部符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11709505/

相关文章:

c++ - 将构造函数添加到我的结构时不断出现链接器错误

c++ - 递归调用可变参数函数的链接器错误

ios - 导入 Muhku 库

c - 对 `function' 的 undefined reference

C++ - 无法链接到 VS2015 中的静态库

C++ : Why redeclare a template's generic data type after one use?

arrays - Lisp 变量未绑定(bind)

mysql - SQL "Truncated incorrect INTEGER value"错误

php - PHP解析/语法错误;以及如何解决它们

Terraform - 错误 : extra characters after interpolation expression