Kothari Kothari -4 years ago 94
C Question

Why we use -lpcap with gcc and what is meaning of that?

It is compulsory to use -lpcap with gcc to compile libpcap program, but I don't know what this flag means. Can anybody help me??

Example:

$ gcc lpcap_demo.c -o lpcap_output.o -lpcap


Thank you!!!

Answer Source

gcc -l instructs GCC to link the program with the library given as command-line option, and pcap is the name of libpcap. The lib prefix of the library name is implied, so if you were to write -lpthread you would link with libpthread, a POSIX thread library, -lrt links with librt, which is a real time extension library and so on and so forth :)

So yeah, it is compulsory to compile with -lpcap as long as you are using exported symbols from the pcap library.

Does this answer your question? :)

You can get more information by typing this command in the terminal:

man gcc

... and search for the -l option. Here is the man page on GCC :

http://man7.org/linux/man-pages/man1/gcc.1.html

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download