Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Gtk+/Gnome Application Development
Prev Home Next

Compiling Hello, World

GTK+ comes with a shell script called gtk-config; this script is created when GTK+ is built. Its purpose is to report the compiler flags you need to compile GTK+ programs. The following shell session demonstrates its features:

$ gtk-config --version
$ gtk-config --prefix
$ gtk-config --exec-prefix
$ gtk-config --libs       
-L/home/hp/local/lib -L/usr/X11R6/lib -lgtk -lgdk -rdynamic -lgmodule -lglib -ldl -lXext -lX11 -lm
$ gtk-config --libs gthread
-L/home/hp/local/lib -L/usr/X11R6/lib -lgtk -lgdk -rdynamic -lgmodule -lgthread -lglib -lpthread -ldl -lXext -lX11 -lm
$ gtk-config --cflags 
-I/usr/X11R6/include -I/home/hp/local/lib/glib/include -I/home/hp/local/include

If you're using a Bourne shell variant, such as bash, you can use backticks (not single quotes!) to execute gtk-config and substitute its output. A simple Makefile for compiling Hello, World might look like this:


all: hello.c
        $(CC) `gtk-config --libs` `gtk-config --cflags` -o hello hello.c

        /bin/rm -f *.o *~

Of course, this Makefile is far too simple for real-world applications; the chapter called Creating Your Source Tree describes how to set up a more realistic build using automake and autoconf.

gtk-config allows you to locate GTK+ on the user's system, instead of hard-coding a location in your Makefile. It also comes in handy if you have two versions of GTK+ on your own system; if you install them each in a dedicated directory tree, you can choose one or the other by placing the correct gtk-config in your shell's search path.

Gtk+/Gnome Application Development
Prev Home Next

  Published under free license. Design by Interspire