I am trying to write a makefile for a small project which uses GTK libraries.
# Compiler
cc = gcc
#Options for Development
CFLAGS = `pkg-config --cflags --libs gtk+-2.0`
all: pss
pss : main.o interface.o
# $(cc) $(CFLAGS) -o pss main.o interface.o
main.o : main.c interface.h
interface.o : interface.c
pss
is supposed to be the final executable file. However, the makefile does not create the executable pss
. When I explicitly add the line for creating pss
, then I am getting a linking error.
asheesh:~/Source$ make
gcc `pkg-config --cflags --libs gtk+-2.0` -o pss main.o interface.o
interface.o: In function `interface':
interface.c:(.text+0x1e): undefined reference to `gtk_init'
interface.c:(.text+0x28): undefined reference to `gtk_window_new'
interface.c:(.text+0x38): undefined reference to `gtk_widget_show'
interface.c:(.text+0x3d): undefined reference to `gtk_main'
collect2: ld returned 1 exit status
make: *** [pss] Error 1
How do I create the final executable file using make
?
Changed the makefile to handle library dependencies properly. Still not working.
#Options for Development
CFLAGS = `pkg-config --cflags gtk+-2.0`
#Libraries
LIBS = `pkg-config --libs gtk+-2.0`
all: pss
pss : main.o interface.o
$(cc) $(LIBS) $(CFLAGS) -o pss main.o interface.o
main.o : main.c interface.h
$(cc) $(CFLAGS) -o main.o main.c interface.o
interface.o : interface.c
$(cc) $(CFLAGS) $(LIBS) -o interface.o interface.c