Pcap functions have "undefined reference"

Yahya Uddin picture Yahya Uddin · Nov 24, 2014 · Viewed 19k times · Source

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'

Answer

sehe picture sehe · Nov 24, 2014