开发者

Glade and static linking

开发者 https://www.devze.com 2022-12-14 15:44 出处:网络
If I\'m statically linking a GTK+ program under FreeBSD 8, gtk_builder_add_from_file() suddenly returns with an error:

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_pixb开发者_JAVA百科uf-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)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消