2

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!!!

cha5on
  • 482
  • 4
  • 9
Kothari
  • 91
  • 1
  • 9

1 Answers1

5

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

Morten Jensen
  • 5,818
  • 3
  • 43
  • 55