Sunday, January 16, 2011

learnin

gcc -Wall -g GTKTest.c -o GTKTest `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`

The above is the terminal command to compile my first "hello world" style GTK program. I have seen stuff like this before with pkg-config on other tutorials but never knew what it meant. Thankfully this book is pretty good about explaining the unusual things that pop up - other web sites or books seem to assume that you know what all that means already. So, good on this book.

So the trick is that you want to make sure that all the header files for a GTK program can be seen by the compiler. Unfortunately there are tons of them. You include gtk.h in the program but that header has headers.

If you type in (sans quotes) "pkg-config -cflags gtk+-2.0" in the console you get this result:

-pthread -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12

This is the stuff you gotta pass to the compiler, but since this is too much to reasonable type GCC has a neat little trick. Those tic mark things surrounding the pkg-config part of the GCC command will execute whatever is in between them and replace it with the result of that execution (the include pathways, in this case).

Pretty neat! I'm glad I'm getting some other info from this book.

I hit a bit of a problem when I didn't realise that those tics weren't apostrophes.

` is not equal to '

No comments:

Post a Comment