0

我正在编写一个使用Winpcap.I 的网络工具。我正在使用 Visual Studio 2017 。 Winpcap是一个外部库,我必须在我的程序中包含pcap.h. 我当然知道这些:

(1) 编译器需要知道头文件的位置。

(2) 链接器需要知道.lib文件所在的位置,以及lib文件名

所以对于第一个,我在下一步中添加包含目录的路径(如图像) 在此处输入图像描述

最后一个我这样做了 在此处输入图像描述

现在我有一个像这样的通信器类

#include<pcap.h>
#pragma once
class Communicator
{
    public:
    pcap_if_t *alldevs;
    pcap_t *fp;
    int findAllDevice(void);
    //int openAdapter(char* _name);
    //void readNexLoop(void);
    //void startCommunicator(void);
    Communicator();
    ~Communicator();
};

.cpp 文件:

#include "stdafx.h"
#include "Communicator.h"

//#include<thread>
Communicator::Communicator()
{
}


Communicator::~Communicator()
{
}
int Communicator::findAllDevice()
{
int result = -1;
char errbuf[PCAP_ERRBUF_SIZE + 1];

result = pcap_findalldevs(&alldevs, errbuf);
//result = pcap_findalldevs(&alldevs, errbuf);
//pcap_freealldevs(alldevs);
return result;
}

但是当我构建它时,有错误

    Error   LNK2019 unresolved external symbol _pcap_findalldevs referenced in function "public: int 
            __thiscall Communicator::findAllDevice(void)" (?findAllDevice@Communicator@@QAEHXZ)  
    MobinServer2.0  D:\MobinServer2.0\MobinServer2.0\Communicator.obj   1   

任何人都可以对此有所了解,我做错了什么?我需要帮助这个请帮我解决。谢谢

4

1 回答 1

1

为其他库添加目录是不够的,您还需要将库本身添加为依赖项。头文件有时会代表您执行此操作,而这个显然没有。

于 2020-09-12T10:07:42.800 回答