Skip navigation

I found Raph Levien’s GTK+ Hello World page, typed in the code, and attempted to compile it. Unfortunately, while the code itself is functional, the suggested Makefile is definitely not. These days, we use the pkg-config program to generate flags for libraries like GTK+ to the compiler and linker, rather than hard-coding them. Also, some of the directory-finding stuff for libraries and headers is unnecessary today.

Thus, while you can use his “helloworld.c” program, you’ll probably want to use my Makefile instead, which follows.

CC = gcc
CFLAGS = -O2 -pipe
CFLAGS += $(shell pkg-config --cflags glib-2.0)
CFLAGS += $(shell pkg-config --cflags gtk+-2.0)
LIBS = $(shell pkg-config --libs gtk+-2.0)
LIBS += $(shell pkg-config --libs glib-2.0)
#LDFLAGS = $(LIBS) -lgtk -lgdk -lglib -lX11 -lXext -lm

OBJS = gtk_helloworld.o

helloworld:     $(OBJS)
        $(CC) $(OBJS) -o gtk_helloworld $(LDFLAGS)

        rm -f *.o *~ gtk_helloworld

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: