To compile use:
gcc -Wall -g helloworld.c -o helloworld `gtk-config --cflags` \
`gtk-config --libs`
This uses the program gtk-config, which comes with GTK. This program "knows" what compiler switches are needed to compile programs that use GTK. gtk-config --cflags will output a list of include directories for the compiler to look in, and gtk-config --libs will output the list of libraries for the compiler to link with and the directories to find them in. In the above example they could have been combined into a single instance, such as `gtk-config --cflags --libs`.
Note that the type of single quote used in the compile command above is significant.
The libraries that are usually linked in are:
The GTK library (-lgtk), the widget library, based on top of GDK.
The GDK library (-lgdk), the Xlib wrapper.
The gmodule library (-lgmodule), which is used to load run time extensions.
The GLib library (-lglib), containing miscellaneous functions; only g_print() is used in this particular example. GTK is built on top of glib so you will always require this library. See the section on GLib for details.
The Xlib library (-lX11) which is used by GDK.
The Xext library (-lXext). This contains code for shared memory pixmaps and other X extensions.
The math library (-lm). This is used by GTK for various purposes.