-desktop:~/Desktop$ gcc -lpcap test.c -o test
/tmp/cczDYeHY.o: In function `main':
test.c:(.text+0xbc): undefined reference to `pcap_lookupdev'
test.c:(.text+0x11b): undefined reference to `pcap_lookupnet'
test.c:(.text+0x143): undefined reference to `pcap_open_live'
test.c:(.text+0x1a9): undefined reference to `pcap_compile'
test.c:(.text+0x1ef): undefined reference to `pcap_setfilter'
test.c:(.text+0x23a): undefined reference to `pcap_loop'
collect2: error: ld returned 1 exit status
答案1
这个问题已经在堆栈溢出。您应该移至-lpcap
命令末尾。但即使您使用的是 Ubuntu,这个问题也与主题无关,最好将其放在 Stack Overflow 上。