如何解决将'.lib'和'.h'文件添加到项目中后,在Visual Studio 2017中的C ++中使用pcap.h的问题
我正在编程一个使用Winpcap
的网络工具。我正在使用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
任何人都可以阐明这一点,我在做什么错?我需要帮助,请帮助我解决。 谢谢
解决方法
仅为其他库添加目录是不够的,还需要将库本身添加为依赖项。头文件有时会代表您执行此操作,但显然不是。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。