Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pcap functions have "undefined reference"

Tags:

I'm trying to go through this tutorial: http://www.tcpdump.org/pcap.html

Now I have install pcap (code hints and all that is working) using :

sudo apt-get install libpcap-dev 

and so far I have the following code (file name is example_pcap.c):

#include <stdio.h> #include <pcap.h>  int main(int argc, char *argv[]) {     char *dev, errbuf[PCAP_ERRBUF_SIZE];      dev = pcap_lookupdev(errbuf);      return 0; } 

According to many questions I have seen already they said to compile it using this:

gcc -lpcap example_pcap.c -o example_pcap 

However I still get the following error:

example_pcap.c:(.text+0x32): undefined reference to `pcap_lookupdev' 
like image 258
Yahya Uddin Avatar asked Nov 24 '14 15:11

Yahya Uddin


1 Answers

Move -lpcap to the end of the command line

See Why does the order in which libraries are linked sometimes cause errors in GCC?

like image 137
sehe Avatar answered Oct 06 '22 07:10

sehe