Glade 和静态链接
如果我在 FreeBSD 8 下静态链接 GTK+ 程序,gtk_builder_add_from_file()
会突然返回并显示错误:
Invalid object type `GtkWindow'
如何修复该问题?通过动态链接,一切正常。
更新:链接是通过以下方式完成的:
cc -o foobar foo.o bar.o main.o -Wall -pedantic -std=c99 D_THREAD_SAFE -DORBIT2=1 -D_REENTRANT -I/usr/local/include/gtk-2.0 -I/usr/local/lib/gtk-2.0/include -I/usr/local/include/atk-1.0 -I/usr/local/include/cairo -I/usr/local/include/pango-1.0 -I/usr/local/include -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include/pixman-1 -I/usr/local/include/freetype2 -I/usr/local/include/gconf/2 -I/usr/local/include/orbit-2.0 -I/usr/local/include/dbus-1.0 -I/usr/local/include/dbus-1.0/include -DGTK_DISABLE_DEPRECATED=1 -DGDK_DISABLE_DEPRECATED -DGDK_PIXBUF_DISABLE_DEPRECATED -DG_DISABLE_DEPRECATED=1 -DGTK_MULTIHEAD_SAFE=1 -export-dynamic -static -pthread -L/usr/local/lib -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lgio-2.0 -lXinerama -lXi -lXcursor -lXcomposite -lXdamage -lpangoft2-1.0 -lXext -lXfixes -lcairo -lpixman-1 -lpng -lxcb-render-util -lXrender -lxcb-render -lX11 -lxcb -lXau -lXdmcp -lpango-1.0 -lfontconfig -lexpat -lfreetype -lz -lgconf-2 -lORBit-2 -lm -ldbus-1 -lgmodule-2.0 -lgthread-2.0 -lgobject-2.0 -lglib-2.0 -liconv -lintl -lpcre
或者换句话说,在 Makefile 中我有:
CFLAGS := -Wall -pedantic -std=c99 LDFLAGS := -export-dynamic -static CFLAGS += $(shell pkg-config --cflags gtk+-2.0 gconf-2.0) \ -DGTK_DISABLE_DEPRECATED=1 -DGDK_DISABLE_DEPRECATED \ -DGDK_PIXBUF_DISABLE_DEPRECATED -DG_DISABLE_DEPRECATED=1 \ -DGTK_MULTIHEAD_SAFE=1 LDFLAGS += $(shell pkg-config --libs --static gtk+-2.0 gconf-2.0) -lintl -lpcre ... $(NAME): $(OBJ) cc -o $@ $^ $(CFLAGS) $(LDFLAGS)
If I'm statically linking a GTK+ program under FreeBSD 8, gtk_builder_add_from_file()
suddenly returns with an error:
Invalid object type `GtkWindow'
How to fix that? With dynamic linking everything works fine.
Update: linking is done by:
cc -o foobar foo.o bar.o main.o -Wall -pedantic -std=c99 D_THREAD_SAFE -DORBIT2=1 -D_REENTRANT -I/usr/local/include/gtk-2.0 -I/usr/local/lib/gtk-2.0/include -I/usr/local/include/atk-1.0 -I/usr/local/include/cairo -I/usr/local/include/pango-1.0 -I/usr/local/include -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include/pixman-1 -I/usr/local/include/freetype2 -I/usr/local/include/gconf/2 -I/usr/local/include/orbit-2.0 -I/usr/local/include/dbus-1.0 -I/usr/local/include/dbus-1.0/include -DGTK_DISABLE_DEPRECATED=1 -DGDK_DISABLE_DEPRECATED -DGDK_PIXBUF_DISABLE_DEPRECATED -DG_DISABLE_DEPRECATED=1 -DGTK_MULTIHEAD_SAFE=1 -export-dynamic -static -pthread -L/usr/local/lib -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lgio-2.0 -lXinerama -lXi -lXcursor -lXcomposite -lXdamage -lpangoft2-1.0 -lXext -lXfixes -lcairo -lpixman-1 -lpng -lxcb-render-util -lXrender -lxcb-render -lX11 -lxcb -lXau -lXdmcp -lpango-1.0 -lfontconfig -lexpat -lfreetype -lz -lgconf-2 -lORBit-2 -lm -ldbus-1 -lgmodule-2.0 -lgthread-2.0 -lgobject-2.0 -lglib-2.0 -liconv -lintl -lpcre
or in another words, in Makefile I have:
CFLAGS := -Wall -pedantic -std=c99 LDFLAGS := -export-dynamic -static CFLAGS += $(shell pkg-config --cflags gtk+-2.0 gconf-2.0) \ -DGTK_DISABLE_DEPRECATED=1 -DGDK_DISABLE_DEPRECATED \ -DGDK_PIXBUF_DISABLE_DEPRECATED -DG_DISABLE_DEPRECATED=1 \ -DGTK_MULTIHEAD_SAFE=1 LDFLAGS += $(shell pkg-config --libs --static gtk+-2.0 gconf-2.0) -lintl -lpcre ... $(NAME): $(OBJ) cc -o $@ $^ $(CFLAGS) $(LDFLAGS)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,不支持将 gtk+ 静态链接到应用程序。你可能会遇到很多棘手的问题。
GtkBuilder 需要能够
dlopen
您的库,您需要确保相关库中的所有符号也由您的二进制文件导出。在 ELF 系统上,您必须将-export-dynamic
/-Wl,-export-dynamic
传递给链接器/gcc。First of all linking gtk+ against an application statically is not supported. You are likely to run into a lot of hairy problems.
GtkBuilder needs to be able to
dlopen
your library, you need to make sure that all he symbols from the related libraries are also exported by your binary. On ELF systems you'll have to pass in the-export-dynamic
/-Wl,-export-dynamic
to the linker/gcc.