[cairo] libraries required

Tor Lillqvist tml at iki.fi
Mon Jul 13 02:03:14 PDT 2009


> For example when using GTK the simplest way to compile an app is
> something like this:
>
> gcc `pkg-config --cflags --libs gtk+-2.0` -Wall -W app.c -o app

Unfortunately, that way to use pkg-config, even if it is a very
popular and widely spread meme, works only on Linux, more or less.
There are many Unix systems where it doesn't work. The more portable
way to use pkg-config in a gcc command line is to invoke it twice on
the command line, once with --cflags and once with --libs. In general,
the list of libraries to link with should go *after* the list of
object files (or source files). This is how it always has beenm and
this is also what gcc documentation says. Thus:

gcc `pkg-config --cflags gtk+-2.0` -Wall -W app.c `pkg-config --libs
gtk+-2.0` -o app

and if one reorders the options to be in a more traditional order (and
perhaps one required by some compilers?), this:

gcc -Wall -W  -o app `pkg-config --cflags gtk+-2.0` app.c `pkg-config
--libs gtk+-2.0`

and in general, in Make syntax, something like:

$(CC) $(CFLAGS) -o app `pkg-config --cflags gtk+-2.0` $(SOURCES)
$(OBJECTS)  `pkg-config --libs gtk+-2.0`

I really wish the pkg-config author(s) had prevented the simultaneous
use of both --cflags and --libs. To change it now would be a
regression, sigh.

--tml


More information about the cairo mailing list