I’m new in objective-c and makefiles, currently I’m trying to get an objective-c and Gtk+ “hello world” to compile via make.
The make code is as follows
# Suffixes
.SUFFIXES: .o .m
.m.o:
$(CC) -c $(CFLAGS) $<
# Macros
CC = gcc
CFLAGS = -g
GTKFLAGS= `pkg-config --cflags --libs gtk+-2.0`
LIBS = -lobjc
SRC = main.m MainWindow.m
OBJ = main.o MainWindow.o
PROG = gnulog514
# Explicit rule
all: hist
hist: $(OBJ)
$(CC) $(CFLAGS) -o main $(OBJ) $(GTKFLAGS) $(LIBS)
# Implicit rules
MainWindow.o: MainWindow.h MainWindow.m
and I get the following output after make.
gcc -c -g main.m
In file included from main.m:1:0:
MainWindow.h:1:20: fatal error: gtk/gtk.h: No such file or directory
compilation terminated.
make: *** [main.o] Error 1
Anything else you may need just ask.
UPDATE:
I’ve got something else that may help,
when issuing the command
$ gcc `pkg-config --cflags --libs gtk+2.0` -lgnustep-base -fconstant-string-class=NSConstantString -o "./myprogram" $(find . -name '*.m') -I /usr/include/GNUstep/ -L /usr/lib/GNUstep/ -std=c99 -O3
(Got the error gtk+2.0 to gtk+-2.0)I get the following output
Package gtk+2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk+2.0' found
In file included from ./main.m:1:0:
./MainWindow.h:1:20: fatal error: gtk/gtk.h: No such file or directory
compilation terminated.
In file included from ./MainWindow.m:1:0:
./MainWindow.h:1:20: fatal error: gtk/gtk.h: No such file or directory
compilation terminated.
I’ll get that fixed and come back here to keeping updated this question until solution.
I got it to work. Long story short instead of using Foundations headers I use objc headers.
My Makefile looks like that
And if you want to try by yourself my main.m
my MainWindow.h
my MainWindow.m
Just put all the files in the same folder and run make, you’ll get a compiled file called glog514, then execute it and you’ll get the nice gtk window.
./glog514
cheers,