title: How to fix "undefined reference" linker errors that occur in spite of passing the right flags?
body: <p>I'm trying to compile <a href="http://code.google.com/p/n1mda-dev/source/browse/#svn/trunk/pirni" rel="nofollow">this C program called Pirni</a>, which was originally made for iPhone, and I would like to run it on linux Ubuntu 12.04 LTS. It's very short, (3 C files and 1 header file). But I get the following errors. I do have <code>libpcap-dev</code> installed and I did include <code>-lpcap</code> so I don't know what could be wrong.</p>
  
  <pre><code>gcc -Wall -pthread -lpcap pirni.c threads.c sniffer.c -o pirni -lnet
  pirni.c: In function ‘set_forwarding’:
  pirni.c:31:2: warning: implicit declaration of function ‘sysctlbyname’ [-Wimplicit-function-declaration]
  /tmp/cc3sf284.o: In function `set_forwarding':
  pirni.c:(.text+0xfd): undefined reference to `sysctlbyname'
  /tmp/ccvGjyMo.o: In function `processPacket':
  sniffer.c:(.text+0x1b): undefined reference to `pcap_dump'
  /tmp/ccvGjyMo.o: In function `initSniffer':
  sniffer.c:(.text+0xfa): undefined reference to `pcap_open_live'
  sniffer.c:(.text+0x15a): undefined reference to `pcap_lookupnet'
  sniffer.c:(.text+0x1af): undefined reference to `pcap_compile'
  sniffer.c:(.text+0x1dd): undefined reference to `pcap_setfilter'
  sniffer.c:(.text+0x222): undefined reference to `pcap_dump_open'
  sniffer.c:(.text+0x27c): undefined reference to `pcap_loop'
  collect2: ld returned 1 exit status
  make: *** [main] Error 1
  </code></pre>