gcc - 链接可执行文件时查找共享库依赖项

标签 gcc cross-compiling gstreamer ld

我正在尝试在 Ubuntu 12.04(32 位)构建系统上为 ARM 主机交叉编译 gstreamer。 i686-linux-gnu GCC 不会发生我将要描述的所有情况。我正在使用这个 gcc 在 Ubuntu 12.04 上进行编译:

> arm-linux-gnueabihf-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/4.6/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5'
--with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6
--enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/arm-linux-gnueabihf/include/c++/4.6.3 --libdir=/usr/lib
--enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes
--enable-gnu-unique-object --enable-plugin --enable-objc-gc --enable-multilib
--disable-sjlj-exceptions --with-arch=armv7-a --with-float=hard --with-fpu=vfpv3-d16
--with-mode=thumb --disable-werror --enable-checking=release --build=i686-linux-gnu
--host=i686-linux-gnu --target=arm-linux-gnueabihf --program-prefix=arm-linux-gnueabihf-
--includedir=/usr/arm-linux-gnueabihf/include
--with-headers=/usr/arm-linux-gnueabihf/include
--with-libs=/usr/arm-linux-gnueabihf/lib
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)

还有这个 ld:

arm-linux-gnueabihf-ld -v GNU ld (GNU Binutils for Ubuntu) 2.22

GCC 是从默认的 Ubuntu 12.04 PPA 安装的。当构建系统开始链接 gst-discoverer-1.0 可执行文件时,我收到以下错误:

/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../../arm-linux-gnueabihf/bin/ld: warning: liborc-0.4.so.0, needed by ../gst-libs/gst/video/.libs/libgstvideo-1.0.so, not found (try using -rpath or -rpath-link)
../gst-libs/gst/video/.libs/libgstvideo-1.0.so: undefined reference to `orc_program_compile'
../gst-libs/gst/video/.libs/libgstvideo-1.0.so: undefined reference to `orc_program_set_backup_function'
../gst-libs/gst/video/.libs/libgstvideo-1.0.so: undefined reference to `orc_program_new_from_static_bytecode'
../gst-libs/gst/video/.libs/libgstvideo-1.0.so: undefined reference to `orc_program_free'
../gst-libs/gst/video/.libs/libgstvideo-1.0.so: undefined reference to `orc_once_mutex_lock'
../gst-libs/gst/video/.libs/libgstvideo-1.0.so: undefined reference to `orc_program_take_code'
../gst-libs/gst/video/.libs/libgstvideo-1.0.so: undefined reference to `orc_once_mutex_unlock'
collect2: ld returned 1 exit status

gst-discoverer-1.0 依赖于 libgstvideo-1.0.so。 libgstvideo-1.0.so(在此过程的早期已成功构建)依赖于 liborc-0.4.so。使用arm-linux-gnueabihf-readelf -a 检查 libgstvideo-1.0.so 会产生以下代码片段:

Dynamic section at offset 0x29ed8 contains 33 entries:
  Tag        Type                         Name/Value
 0x00000001 (NEEDED)                     Shared library: [libgstbase-1.0.so.0]
 0x00000001 (NEEDED)                     Shared library: [libgstreamer-1.0.so.0]
 0x00000001 (NEEDED)                     Shared library: [libgobject-2.0.so.0]
 0x00000001 (NEEDED)                     Shared library: [libglib-2.0.so.0]
 0x00000001 (NEEDED)                     Shared library: [liborc-0.4.so.0]
 0x00000001 (NEEDED)                     Shared library: [libgcc_s.so.1]
 0x00000001 (NEEDED)                     Shared library: [libpthread.so.0]
 0x00000001 (NEEDED)                     Shared library: [libc.so.6]
 0x0000000e (SONAME)                     Library soname: [libgstvideo-1.0.so.0]
 0x0000000f (RPATH)                      Library rpath: [/home/test/gst/gstreamer/gstreamer/libs/gst/base/.libs:/
home/test/gst/gstreamer/gstreamer/gst/.libs:/home/test/gst/gstreamer/orc/orc/.libs]

RPATH 条目中 liborc-0.4.so 的路径正确。 gst-discoverer-1.0 的链接行不包含对 liborc 的引用,因为它不直接依赖于它(仅通过 libgstvideo-1.0.so 间接依赖)。我尝试将“-rpath-link=/home/test/gst/gstreamer/orc/orc/.libs”添加到我的 LDFLAGS,但它不起作用。关于为什么交叉编译链接器无法找到此共享库的依赖项有什么想法吗?

最佳答案

看来我走在正确的轨道上,但我将 -rpath-link 传递给 ld (在我的配置行上使用 LDFLAGS)。由于实际上是 gcc 进行链接,因此我需要使用 CFLAGS 和 -Wl 参数,如下所示:

./configure CFLAGS="-Wl,-rpath=/home/test/gst/gstreamer/orc/orc/libs"

According to some ,交叉链接器中可能存在错误。

关于gcc - 链接可执行文件时查找共享库依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16593519/

相关文章:

python - C++ Python 模块未使用 g++ 链接到 Python

c++ - gcc:抑制来自 C++ 代码的 [默认启用] 警告

海湾合作委员会; Aarch64; ARMV8;启用加密; -mcpu=cortex-a53+加密

c++ - 汇编语法和平台之间的关系是什么

linux - 是否可以在启用 v8 快照的情况下交叉编译 node.js?

c++ - GStreamer:rtpjpegdepay/jpegdec 输出的帧颜色错误

video-streaming - gst-launch-1.0 无元素 "hlssink"错误

c - 如何使单个 "makefile"创建 3 个输出二进制文件

linux - 如何使用 crosstool-NG 更改 GCC 'Canadian cross' 编译的主机类型

c - 如何在gstreamer中录制音频和视频