我对makefile以及我使用的库(Gtk,Gdk和OpenCL)创建一个程序应该显示mandelbrot设置为动态图像的程序非常新。
我已经根据我教授提供的makefile创建了这个make文件。我在makefile中遇到的问题是由于我的教授正在使用其他操作系统等等。
所以,我已经将他的makefile更改为我的新makefile:
GTK_PACKAGES=gdk-pixbuf-2.0 gtk+-2.0
GTK_CFLAGS=$(shell pkg-config --cflags $(GTK_PACKAGES))
GTK_LIBS=$(shell pkg-config --libs $(GTK_PACKAGES))
CFLAGS=-g -Wall -O2 -std=c99 $(GTK_CFLAGS)
LIBS=$(GTK_LIBS)
PROGS=opencl_mandelbrot
.PHONY: all
all: $(PROGS)
%: %.c
$(CC) $(CFLAGS) $(LDFLAGS) $*.c -framework OpenCL -o $@
%.o: %.c
$(CC) $(CFLAGS) -c $*.c -o $@
opencl_mandelbrot: opencl_mandelbrot.o opencl_util.o
$(CC) $(CFLAGS) $(LDFLAGS) opencl_mandelbrot.o opencl_util.o -framework OpenCL -o $@
.PHONY: clean
clean:
rm -f *.o $(PROGS)
但是当我尝试在终端上输入make
时,我发现了以下错误:
cc -g -Wall -O2 -std=c99 -D_REENTRANT -I/opt/X11/include/cairo -I/opt/X11/include/pixman-1 -I/opt/X11/include -I/opt/X11/include/freetype2 -I/opt/X11/include/libpng15 -I/opt/X11/include -I/usr/local/Cellar/gdk-pixbuf/2.32.3/include/gdk-pixbuf-2.0 -I/usr/local/Cellar/gtk+/2.24.30/include/gtk-2.0 -I/usr/local/Cellar/gtk+/2.24.30/lib/gtk-2.0/include -I/usr/local/Cellar/pango/1.38.1/include/pango-1.0 -I/usr/local/Cellar/harfbuzz/1.2.6/include/harfbuzz -I/usr/local/Cellar/pango/1.38.1/include/pango-1.0 -I/usr/local/Cellar/atk/2.18.0_1/include/atk-1.0 -I/usr/local/Cellar/libpng/1.6.21/include/libpng16 -I/usr/local/Cellar/glib/2.46.2/include/glib-2.0 -I/usr/local/Cellar/glib/2.46.2/lib/glib-2.0/include -I/usr/local/opt/gettext/include -c opencl_mandelbrot.c -o opencl_mandelbrot.o
cc -g -Wall -O2 -std=c99 -D_REENTRANT -I/opt/X11/include/cairo -I/opt/X11/include/pixman-1 -I/opt/X11/include -I/opt/X11/include/freetype2 -I/opt/X11/include/libpng15 -I/opt/X11/include -I/usr/local/Cellar/gdk-pixbuf/2.32.3/include/gdk-pixbuf-2.0 -I/usr/local/Cellar/gtk+/2.24.30/include/gtk-2.0 -I/usr/local/Cellar/gtk+/2.24.30/lib/gtk-2.0/include -I/usr/local/Cellar/pango/1.38.1/include/pango-1.0 -I/usr/local/Cellar/harfbuzz/1.2.6/include/harfbuzz -I/usr/local/Cellar/pango/1.38.1/include/pango-1.0 -I/usr/local/Cellar/atk/2.18.0_1/include/atk-1.0 -I/usr/local/Cellar/libpng/1.6.21/include/libpng16 -I/usr/local/Cellar/glib/2.46.2/include/glib-2.0 -I/usr/local/Cellar/glib/2.46.2/lib/glib-2.0/include -I/usr/local/opt/gettext/include opencl_mandelbrot.o opencl_util.o -framework OpenCL -o opencl_mandelbrot
Undefined symbols for architecture x86_64:
"_g_object_unref", referenced from:
_reallocate_pixbufs in opencl_mandelbrot.o
"_g_type_check_instance_cast", referenced from:
_main in opencl_mandelbrot.o
"_gdk_draw_pixbuf", referenced from:
_draw_mandelbrot_full_with_gpu in opencl_mandelbrot.o
"_gdk_pixbuf_get_height", referenced from:
_reallocate_pixbufs in opencl_mandelbrot.o
_recenter in opencl_mandelbrot.o
_draw_mandelbrot_full_with_gpu in opencl_mandelbrot.o
"_gdk_pixbuf_get_n_channels", referenced from:
_draw_mandelbrot_full_with_gpu in opencl_mandelbrot.o
"_gdk_pixbuf_get_pixels", referenced from:
_draw_mandelbrot_full_with_gpu in opencl_mandelbrot.o
"_gdk_pixbuf_get_rowstride", referenced from:
_reallocate_pixbufs in opencl_mandelbrot.o
_draw_mandelbrot_full_with_gpu in opencl_mandelbrot.o
"_gdk_pixbuf_get_width", referenced from:
_reallocate_pixbufs in opencl_mandelbrot.o
_recenter in opencl_mandelbrot.o
_draw_mandelbrot_full_with_gpu in opencl_mandelbrot.o
"_gdk_pixbuf_new", referenced from:
_reallocate_pixbufs in opencl_mandelbrot.o
"_gtk_init", referenced from:
_main in opencl_mandelbrot.o
"_gtk_main", referenced from:
_main in opencl_mandelbrot.o
"_gtk_main_quit", referenced from:
_destroy_window in opencl_mandelbrot.o
_keyboard_input in opencl_mandelbrot.o
"_gtk_object_get_type", referenced from:
_main in opencl_mandelbrot.o
"_gtk_signal_connect_full", referenced from:
_main in opencl_mandelbrot.o
"_gtk_widget_set_events", referenced from:
_main in opencl_mandelbrot.o
"_gtk_widget_show_all", referenced from:
_main in opencl_mandelbrot.o
"_gtk_window_get_type", referenced from:
_main in opencl_mandelbrot.o
"_gtk_window_new", referenced from:
_main in opencl_mandelbrot.o
"_gtk_window_resize", referenced from:
_main in opencl_mandelbrot.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [opencl_mandelbrot] Error 1
即使我已使用gtk
安装brew
,但我猜问题与链接顺序或类似内容有关......
感谢您的帮助!
答案 0 :(得分:1)
opencl_mandelbrot: opencl_mandelbrot.o opencl_util.o
$(CC) $(CFLAGS) $(LDFLAGS) $(LIBS) opencl_mandelbrot.o opencl_util.o -framework OpenCL -o $@
你错过了LIBS
答案 1 :(得分:1)
您将GTK +链接器标志分配给LIBS
变量,但在您的规则中使用LDFLAGS
变量,因此您会收到链接器错误,因为链接器无法解析符号,因为它未指示查找他们在战斗场所。
变化:
LIBS=$(GTK_LIBS)
到
LDFLAGS=$(GTK_LIBS)
或将$(LIBS)
添加到链接器规则中。
答案 2 :(得分:1)
通过尝试重新发明内置规则,您最终添加了自己的错误,您不需要告诉make如何编译或链接,它已经知道,您需要做的就是设置正确的变量
GTK_PACKAGES := gdk-pixbuf-2.0 gtk+-2.0
GTK_CFLAGS := $(shell pkg-config --cflags $(GTK_PACKAGES))
GTK_LIBS := $(shell pkg-config --libs $(GTK_PACKAGES))
CFLAGS := -g -Wall -O2 -std=c99 $(GTK_CFLAGS)
LDLIBS := $(GTK_LIBS)
PROGS := opencl_mandelbrot
.PHONY: all clean
all: $(PROGS)
opencl_mandelbrot: LDFLAGS += -framework OpenCL
opencl_mandelbrot: opencl_mandelbrot.o opencl_util.o
clean: ; $(RM) *.o $(PROGS)
当使用通配符删除文件时,请注意,如果您要重新分发代码,那么这是一个坏主意。