libpcap 函数有问题吗?
#include <stdio.h>
#include <pcap.h>
int main(int argc,char* argv[])
{
char* dev=argv[1];
char errbuf[PCAP_ERRBUF_SIZE];
dev=pcap_lookupdev(errbuf);
if(dev==NULL) {
fprintf(stderr,"Couldn't find default device: %s\n",errbuf);
return 0;
}
printf("Device: %s\n",dev);
return 0;
}
编译时:
$ cc pcap1.c
/tmp/ccZLrRlF.o: In function `main':
pcap1.c:(.text+0x37): undefined reference to `pcap_lookupdev'
collect2: ld returned 1 exit status
libpcap 库的其他函数也会发生这种情况。您能给我解释一下这个问题以及纠正它的方法吗?提前致谢...
#include <stdio.h>
#include <pcap.h>
int main(int argc,char* argv[])
{
char* dev=argv[1];
char errbuf[PCAP_ERRBUF_SIZE];
dev=pcap_lookupdev(errbuf);
if(dev==NULL) {
fprintf(stderr,"Couldn't find default device: %s\n",errbuf);
return 0;
}
printf("Device: %s\n",dev);
return 0;
}
On compiling:
$ cc pcap1.c
/tmp/ccZLrRlF.o: In function `main':
pcap1.c:(.text+0x37): undefined reference to `pcap_lookupdev'
collect2: ld returned 1 exit status
This is happening with other functions of the libpcap
library as well. Can you please explain the problem to me and a way to correct it? Thanks in advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您在编译时没有链接 pcap 库,因此您尝试使用的函数都不可用。
如果您尚未在标准库路径中的某个位置安装
libpcap
,则还需要添加它Because you're not linking the pcap library when you're compiling, therefore none of the functions you're trying to use are available.
If you haven't installed
libpcap
somewhere in the standard library path, you would need to add that as well我遇到了这个错误,我刚刚解决了它。
我正在 Debian 7 上工作,所以这就是我所做的:
1 - 安装 libpcap,您可以在此链接中找到如何操作 安装 libpcap
!!!!!! 时遇到了一些问题
安装了flex(sudo apt-get install bison),因为我在安装libpcap
2 - gcc test.c -lpcap返回了这个错误“collect2:ld返回1退出状态”
3 - 安装了libpcap-devel(sudo apt-get)安装 libpcap-dev)
,下次就可以了,
希望这对您有帮助。
祝你好运
I had this Error and I have just solved it.
I am working on Debian 7 so here is what I have done:
1 - insaled the libpcap you find how in this link install libpcap
!!!!!! installed flex (sudo apt-get install bison) because I had some problems while
installing libpcap
2 - gcc test.c -lpcap that returned this error " collect2: ld returned 1 exit status "
3 - installed libpcap-devel (sudo apt-get install libpcap-dev)
and it went through the next time
I hope this is going to be of help to you.
good luck