Re: Compiling my 1st GTK+ program



Maya wrote:

OK, I have a very simple program that goes as follows:
------------ base.c ---------------------
#include <gtk/gtk.h>

int main( int   argc, char *argv[] ){
   GtkWidget *window;
   gtk_init (&argc, &argv);
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_widget_show  (window);
   gtk_main ();
   return 0;
}
-------------- eof -----------------------



With the help of Todd and the litle bit I could find about writing Makefiles I wrote the following script to 
compile the above program:
----------- Makefile  ----------
# Compiler name
CC=gcc

# Flagas
CFLAGS = -Wall -g -ansi `pkg-config --cflags --libs gtk+-2.0`
LDLIBS = `pkg-config --libs gtk+-2.0`

# Variables
OBJS = base.o EXEC = Base

#Application name
all: $(OBJS)
   $(CC) $(LDLIBS) $(OBJS) -o $(EXEC)

# Thanks tod :)
$(EXEC): $(OBJS)

base.o: $(CC) $(CFLAGS) -c base.c

clean:
   rm -f $(OBJS)
   rm -f $(EXEC)

PHONY: clean
--------- eof -------------

The program compiles and creates a 'base.o' file, but I get the following error:

base.o(.text+0x44): In function `main':
/home/Jamil/dev/jme/tmp/GTK_TST/base.c:7: undefined reference to `_gtk_init_abi_check'
base.o(.text+0x50):/home/Jamil/dev/jme/tmp/GTK_TST/base.c:9: undefined reference to `_gtk_window_new'
base.o(.text+0x5e):/home/Jamil/dev/jme/tmp/GTK_TST/base.c:10: undefined reference to `_gtk_widget_show'
base.o(.text+0x63):/home/Jamil/dev/jme/tmp/GTK_TST/base.c:12: undefined reference to `_gtk_main'
collect2: ld returned 1 exit status
make: *** [all] Error 1


I am not an expert, but it looks like the linker is having problems finding the gtk+ libraries, am I right? It is irrelevant if I am right or not; I would not know how to fix problem anyway!
Any help would be very much appreciated.

Thanks Todd for the help with the Makefile, I really don't know much about Makefiles, but little by little 
all this stuff is falling into place

Maya,

# Compiler name
CC=gcc # usually not needed

CFLAGS = -Wall -g -ansi `pkg-config --cflags --libs gtk+-2.0`  # compile time flags for .c files use CXXFLAGS 
for .cc or .cpp
LDFLAGS = `pkg-config --libs gtk+-2.0`  # link time flags that get used during the link step

OBJS = base.o  # you can list all the object files, which have corresponding .c,.cpp,and .cc files here
EXEC = base  # by keeping this name the same as at least one of the object files listed above you can make 
use of implicit rules

# all lets you list 'all' the targets you want to be run when you type 'make'
all: $(EXEC)

# This is all you need it will derive the rest for you
$(EXEC): $(OBJS)

clean:
   rm -f $(EXEC) $(OBJS) # this can all be on the same line

PHONY: clean # usually not needed






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]