为 Objective-C 和 gtk 创建 makefile
我是 Objective-C 和 makefile 的新手,目前我正在尝试通过 make 编译 Objective-C 和 Gtk+“hello world”。 make 代码如下
# 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
,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
您可能还需要任何其他信息,请尽管询问。
更新:
我还有其他可能有帮助的东西, 发出命令时
$ 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
(收到错误 gtk+2.0 到 gtk+-2.0)我得到以下输出
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'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) lt;
# 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我让它工作了。长话短说,我不使用 Foundations 标头,而是使用 objc 标头。
我的 Makefile 看起来像这样
如果你想自己尝试 my main.m
my MainWindow.h
my MainWindow.m
只需将所有文件放在同一个文件夹中并运行 make,你将得到一个名为 glog514 的编译文件,然后执行它你会得到漂亮的 gtk 窗口。
./glog514
干杯,
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,