我为我的raspbian制作了一个带有crosstool-ng的交叉编译器。它成功编译了一个hello单词测试程序,但是当我编译我的gtk测试程序时(使用来自raspberry pi的gtk库)它编译好了,但是当我尝试在树莓中运行它时我得到了这个:
pi@raspberrypi ~ $ ./gtk_test
gtk_test: symbol lookup error: gtk_test: undefined symbol: gtk_progress_get_type
我的ldd输出似乎很好:
pi@raspberrypi ~ $ ldd ./gtk_test
/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so (0xb6f33000)
libgtk-3.so.0 => /usr/lib/arm-linux-gnueabihf/libgtk-3.so.0 (0xb6ac0000)
libgdk-3.so.0 => /usr/lib/arm-linux-gnueabihf/libgdk-3.so.0 (0xb6a29000)
libatk-1.0.so.0 => /usr/lib/arm-linux-gnueabihf/libatk-1.0.so.0 (0xb6a04000)
libgio-2.0.so.0 => /usr/lib/arm-linux-gnueabihf/libgio-2.0.so.0 (0xb68c9000)
libpangocairo-1.0.so.0 => /usr/lib/arm-linux-gnueabihf/libpangocairo-1.0.so.0 (0xb68b7000)
libgdk_pixbuf-2.0.so.0 => /usr/lib/arm-linux-gnueabihf/libgdk_pixbuf-2.0.so.0 (0xb6892000)
libcairo-gobject.so.2 => /usr/lib/arm-linux-gnueabihf/libcairo-gobject.so.2 (0xb6884000)
libpango-1.0.so.0 => /usr/lib/arm-linux-gnueabihf/libpango-1.0.so.0 (0xb6842000)
libcairo.so.2 => /usr/lib/arm-linux-gnueabihf/libcairo.so.2 (0xb6756000)
libgobject-2.0.so.0 => /usr/lib/arm-linux-gnueabihf/libgobject-2.0.so.0 (0xb6706000)
libglib-2.0.so.0 => /lib/arm-linux-gnueabihf/libglib-2.0.so.0 (0xb6613000)
libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0xb65ee000)
libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0xb65ce000)
libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6495000)
libgmodule-2.0.so.0 => /usr/lib/arm-linux-gnueabihf/libgmodule-2.0.so.0 (0xb6488000)
libX11.so.6 => /usr/lib/arm-linux-gnueabihf/libX11.so.6 (0xb6372000)
libXi.so.6 => /usr/lib/arm-linux-gnueabihf/libXi.so.6 (0xb635d000)
libXcomposite.so.1 => /usr/lib/arm-linux-gnueabihf/libXcomposite.so.1 (0xb6352000)
libXdamage.so.1 => /usr/lib/arm-linux-gnueabihf/libXdamage.so.1 (0xb6347000)
libXfixes.so.3 => /usr/lib/arm-linux-gnueabihf/libXfixes.so.3 (0xb6339000)
libatk-bridge-2.0.so.0 => /usr/lib/arm-linux-gnueabihf/libatk-bridge-2.0.so.0 (0xb630f000)
libpangoft2-1.0.so.0 => /usr/lib/arm-linux-gnueabihf/libpangoft2-1.0.so.0 (0xb62f6000)
libfontconfig.so.1 => /usr/lib/arm-linux-gnueabihf/libfontconfig.so.1 (0xb62bd000)
libfreetype.so.6 => /usr/lib/arm-linux-gnueabihf/libfreetype.so.6 (0xb6236000)
libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0xb61c2000)
/lib/ld-linux-armhf.so.3 (0xb6f41000)
libXinerama.so.1 => /usr/lib/arm-linux-gnueabihf/libXinerama.so.1 (0xb61b7000)
libXrandr.so.2 => /usr/lib/arm-linux-gnueabihf/libXrandr.so.2 (0xb61a7000)
libXcursor.so.1 => /usr/lib/arm-linux-gnueabihf/libXcursor.so.1 (0xb6196000)
libwayland-client.so.0 => /usr/lib/arm-linux-gnueabihf/libwayland-client.so.0 (0xb6185000)
libxkbcommon.so.0 => /usr/lib/arm-linux-gnueabihf/libxkbcommon.so.0 (0xb6148000)
libwayland-cursor.so.0 => /usr/lib/arm-linux-gnueabihf/libwayland-cursor.so.0 (0xb6139000)
libXext.so.6 => /usr/lib/arm-linux-gnueabihf/libXext.so.6 (0xb6122000)
librt.so.1 => /lib/arm-linux-gnueabihf/librt.so.1 (0xb6113000)
libz.so.1 => /lib/arm-linux-gnueabihf/libz.so.1 (0xb60f5000)
libselinux.so.1 => /lib/arm-linux-gnueabihf/libselinux.so.1 (0xb60cf000)
libresolv.so.2 => /lib/arm-linux-gnueabihf/libresolv.so.2 (0xb60b2000)
libgthread-2.0.so.0 => /usr/lib/arm-linux-gnueabihf/libgthread-2.0.so.0 (0xb60a8000)
libpng12.so.0 => /lib/arm-linux-gnueabihf/libpng12.so.0 (0xb6080000)
libthai.so.0 => /usr/lib/arm-linux-gnueabihf/libthai.so.0 (0xb6070000)
libpixman-1.so.0 => /usr/lib/arm-linux-gnueabihf/libpixman-1.so.0 (0xb5fd8000)
libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0xb5fcd000)
libxcb-shm.so.0 => /usr/lib/arm-linux-gnueabihf/libxcb-shm.so.0 (0xb5fc3000)
libxcb-render.so.0 => /usr/lib/arm-linux-gnueabihf/libxcb-render.so.0 (0xb5fb5000)
libxcb.so.1 => /usr/lib/arm-linux-gnueabihf/libxcb.so.1 (0xb5f97000)
libXrender.so.1 => /usr/lib/arm-linux-gnueabihf/libXrender.so.1 (0xb5f85000)
libGL.so.1 => /usr/lib/arm-linux-gnueabihf/libGL.so.1 (0xb5f1f000)
libffi.so.6 => /usr/lib/arm-linux-gnueabihf/libffi.so.6 (0xb5f10000)
libpcre.so.3 => /lib/arm-linux-gnueabihf/libpcre.so.3 (0xb5eb5000)
libatspi.so.0 => /usr/lib/arm-linux-gnueabihf/libatspi.so.0 (0xb5e91000)
libdbus-1.so.3 => /lib/arm-linux-gnueabihf/libdbus-1.so.3 (0xb5e4f000)
libharfbuzz.so.0 => /usr/lib/arm-linux-gnueabihf/libharfbuzz.so.0 (0xb5dfb000)
libexpat.so.1 => /lib/arm-linux-gnueabihf/libexpat.so.1 (0xb5dd1000)
libdatrie.so.1 => /usr/lib/arm-linux-gnueabihf/libdatrie.so.1 (0xb5dc5000)
libXau.so.6 => /usr/lib/arm-linux-gnueabihf/libXau.so.6 (0xb5db9000)
libXdmcp.so.6 => /usr/lib/arm-linux-gnueabihf/libXdmcp.so.6 (0xb5dad000)
libglapi.so.0 => /usr/lib/arm-linux-gnueabihf/libglapi.so.0 (0xb5d76000)
libX11-xcb.so.1 => /usr/lib/arm-linux-gnueabihf/libX11-xcb.so.1 (0xb5d6d000)
libxcb-glx.so.0 => /usr/lib/arm-linux-gnueabihf/libxcb-glx.so.0 (0xb5d56000)
libxcb-dri2.so.0 => /usr/lib/arm-linux-gnueabihf/libxcb-dri2.so.0 (0xb5d4a000)
libxcb-dri3.so.0 => /usr/lib/arm-linux-gnueabihf/libxcb-dri3.so.0 (0xb5d40000)
libxcb-present.so.0 => /usr/lib/arm-linux-gnueabihf/libxcb-present.so.0 (0xb5d36000)
libxcb-sync.so.1 => /usr/lib/arm-linux-gnueabihf/libxcb-sync.so.1 (0xb5d2a000)
libxshmfence.so.1 => /usr/lib/arm-linux-gnueabihf/libxshmfence.so.1 (0xb5d21000)
libXxf86vm.so.1 => /usr/lib/arm-linux-gnueabihf/libXxf86vm.so.1 (0xb5d13000)
libdrm.so.2 => /usr/lib/arm-linux-gnueabihf/libdrm.so.2 (0xb5d01000)
libgraphite2.so.3 => /usr/lib/arm-linux-gnueabihf/libgraphite2.so.3 (0xb5ce3000)
当我使用raspberry编译时,我的测试程序工作正常。
我的Makefile:
INCLUDE:=-Irpi_sysroot/usr/include/cairo
INCLUDE+=-Irpi_sysroot/usr/include/atk-1.0
INCLUDE+=-Irpi_sysroot/usr/include/gtk-3.0
INCLUDE+=-Irpi_sysroot/usr/include/glib-2.0
INCLUDE+=-Irpi_sysroot/usr/include/pango-1.0
INCLUDE+=-Irpi_sysroot/usr/include/gdk-pixbuf-2.0
INCLUDE+=-Irpi_sysroot/usr/lib/arm-linux-gnueabihf/glib-2.0/include
INCLUDE+=-Irpi_sysroot/usr/include/at-spi2-atk/2.0
INCLUDE+=-Irpi_sysroot/usr/include/gio-unix-2.0/
INCLUDE+=-Irpi_sysroot/usr/include/harfbuzz
INCLUDE+=-Irpi_sysroot/usr/include/freetype2
INCLUDE+=-Irpi_sysroot/usr/include/pixman-1
INCLUDE+=-Irpi_sysroot/usr/include/libpng12
LIBS:=-Lrpi_sysroot/usr/lib/arm-linux-gnueabihf
LIBS+=-Xlinker -rpath-link=rpi_sysroot/lib/arm-linux-gnueabihf
LIBS+=-Xlinker -rpath-link=rpi_sysroot/usr/lib/arm-linux-gnueabihf
LIBS+=-lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0
LIBS+=-lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0
CC:=./gcc_glibc_2.18/bin/armv6-rpi-linux-gnueabi-gcc
all:
$(CC) $(INCLUDE) -Wall gtk_test.c -o gtk_test $(LIBS)
有人可以解释一下吗?谢谢!
答案 0 :(得分:0)
最后我弄清楚问题是什么:
使用-v -Wl编译,-verbose并查看输出显示rpi_sysroot / usr / lib / arm-linux-gnueabihf / libc.so(脚本)试图链接错误的库。要修复刚打开的libc.so并从中更改:
/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( /lib/arm-linux-gnueabihf/libc.so.6 /usr/lib/arm-linux-gnueabihf/libc_nonshared.a
AS_NEEDED ( /lib/arm-linux-gnueabihf/ld-linux-armhf.so.3 ) )
到此:
/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( ../../../lib/arm-linux-gnueabihf/libc.so.6 ../../../usr/lib/arm-linux-gnueabihf/libc_nonshared.a AS_NEEDED ( ../../../lib/arm-linux-gnueabihf/ld-linux-armhf.so.3 ) )
所以它指向正确的覆盆子库
编辑: 一个更简单的解决方案是删除rpi_sysroot / usr / lib / arm-linux-gnueabihf / libc.so和rpi_sysroot / usr / lib / arm-linux-gnueabihf / libc.a,使链接器回退到libc的交叉编译器版本的.so