5

How do I reliably figure out link flags for libraries? I always end up googling/digging manuals.

Is there a way to list libraries available for linking, with names and/or descriptions?

edit: Linux system, GNU build chain, classics.

salezica
  • 74,081
  • 25
  • 105
  • 166

1 Answers1

4

On most Linux systems, you can use pkg-config to list out the compiler options for a given library. For example:

g++ example.cpp $(pkg-config --cflags --libs libpng)

becomes

g++ example.cpp -I/usr/include/libpng12 -lpng12

Or an example with slightly more complicated output:

$ pkg-config --cflags --libs gthread
-D_REENTRANT -I/usr/include/glib-1.2 -I/usr/lib64/glib/include  -lgthread -lpthread -lglib
BoBTFish
  • 19,167
  • 3
  • 49
  • 76
  • 1
    Also worth noting: `locate --regex pkgconfig/.*pc$` will list available package data for `pkgconfig`. – salezica Feb 12 '13 at 17:20