将'.lib'和'.h'文件添加到项目中后,在Visual Studio 2017中的C ++中使用pcap.h的问题

问题描述

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

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

(2)链接器需要知道.lib文件的位置, 和lib文件名

因此,对于第一个,我在下一步中添加包含目录的路径(如图像)

enter image description here

在最后一个我已经做到了

enter image description here

现在我有一个这样的交流者班

#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   

任何人都可以阐明这一点,我在做什么错?我需要帮助,请帮助我解决。 谢谢

解决方法

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...