我正在尝试将NPCap库安装到Visual Studio中,这样我就可以从文档中运行此代码。
#include "pcap.h"
main()
{
pcap_if_t* alldevs;
pcap_if_t* d;
int i = 0;
char errbuf[PCAP_ERRBUF_SIZE];
/* Retrieve the device list from the local machine */
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL /* auth is not needed */, &alldevs, errbuf) == -1)
{
fprintf(stderr, "Error in pcap_findalldevs_ex: %s\n", errbuf);
exit(1);
}
/* Print the list */
for (d = alldevs; d != NULL; d = d->next)
{
printf("%d. %s", ++i, d->name);
if (d->description)
printf(" (%s)\n", d->description);
else
printf(" (No description available)\n");
}
if (i == 0)
{
printf("\nNo interfaces found! Make sure Npcap is installed.\n");
return;
}
/* We don't need any more the device list. Free it */
pcap_freealldevs(alldevs);}当我运行这段代码时,我得到了许多错误,其中之一是"cannot open source file "pcap/pcap.h"。其他错误说明变量未定义。我相信我没有正确安装这个库。
我在桌面上的同一目录中有.lib文件和.h文件,如此屏幕截图所示。

我还将Visual Studio中的目录更改为适当的文件夹。


根据以下网址中的说明:How to add additional libraries to Visual Studio project?
发布于 2020-01-24 14:39:34
从错误中
“无法打开源文件"pcap/pcap.h”
看起来它需要一个目录结构。包含所有头文件的名为"pcap“的目录。
您是否确认已将此文件夹路径也添加到库目录中。链接以供参考。
https://stackoverflow.com/questions/59826342
复制相似问题