I am running the following libpcap example on Ubuntu, within eclipse:
http://www.tcpdump.org/pcap.html
#include <stdio.h>
#include <pcap.h>
int main(int argc, char *argv[])
{
char *dev, errbuf[PCAP_ERRBUF_SIZE];
dev = pcap_lookupdev(errbuf);
if (dev == NULL) {
fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
return(2);
}
printf("Device: %s\n", dev);
return(0);
}
I included the library path to the libpcap.a file in the eclipse settings for the GCC C++ linker. When I build the project I get:
g++ -L/usr/lib/x86_64-linux-gnu/ -o"test" ./src/test.o -llibpcap.a /usr/bin/ld: cannot find -llibpcap.a collect2: ld returned 1 exit status make: * [test] Error 1
I dont see why the path is /usr/bin/ld when I set it to "/usr/lib/x86_64-linux-gnu/" within the linker library search path (libraries -L)? I also set (libraries -l) within GCC C++ linker to "libpcap.a"
Do I need to set both? Have I done this correctly? My pcap files are located at /usr/lib/x86_64-linux-gnu/
Interestingly if I write non-pcap C++ but include pcap.h the code builds with no errors.