由于缺少pcap定义,无法制定ethping程序

时间:2015-02-05 22:05:15

标签: c linux gcc pcap libpcap

我似乎遇到了构建ethping可执行文件的问题。它找不到pcap.h中定义的任何函数。

起初我认为它没有找到pcap.h,但我检查了$PATH/usr/include是否存在(pcap.h还有一个存根,然后包含pcap/pcap.h,但这看起来也很好。)

我甚至尝试了-I /usr/include-I /usr/include/pcap,但仍然没有运气。

我搜索了很多论坛帖子,但找不到解决方案。这就是我在这里的原因。有什么想法吗?

root:src# gcc -Wall -Werror -ggdb -g -O2 -lpcap -o ethping ethping.o ieee8021ag.o dot1ag_eth.o 
ethping.o: In function `timeout_handler':
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:65: undefined reference to `pcap_breakloop'
ethping.o: In function `main':
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:183: undefined reference to `pcap_open_live'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:202: undefined reference to `pcap_compile'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:203: undefined reference to `pcap_setfilter'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:254: undefined reference to `pcap_next_ex'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:257: undefined reference to `pcap_perror'
collect2: error: ld returned 1 exit status

类似地:

root:src# gcc -Wall -Werror -ggdb -g -O2 -lpcap -I /usr/include/pcap -o ethping ethping.o ieee8021ag.o dot1ag_eth.o 
ethping.o: In function `timeout_handler':
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:65: undefined reference to `pcap_breakloop'
ethping.o: In function `main':
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:183: undefined reference to `pcap_open_live'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:202: undefined reference to `pcap_compile'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:203: undefined reference to `pcap_setfilter'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:254: undefined reference to `pcap_next_ex'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:257: undefined reference to `pcap_perror'
collect2: error: ld returned 1 exit status
root:src# 

2 个答案:

答案 0 :(得分:1)

更改编译行修复它。在最右边放置-lpcap按照建议进行操作。

gcc -Wall -Werror -ggdb -g -O2  -o ethping ethping.o ieee8021ag.o dot1ag_eth.o -lpcap

答案 1 :(得分:0)

您要调用链接器而不包含参数以包含libpcap库,或者未安装库。请参阅http://www.tcpdump.org/以获取库。或者,如果您使用的是受支持的分发版,请使用适用的安装命令:

sudo apt-get install libpcap-dev

sudo yum install libpcap-dev