预链接错误:prelink-cross:简单的hello world示例

时间:2015-06-15 15:27:59

标签: c++ compilation arm cross-compiling prelink

我正在尝试cross-prelink一个简单的hello world程序。我使用交叉编译工具链 arm-2012.03-57-arm-none-linux-gnueabi-i686-pc-linux-gnu 我不确定我是否使用了prelink-cross选项correclty 。如果有人能指出我正确的方向,我会很高兴。有关github上的源代码的更多详细信息。谢谢。

项目目录树

|-arm-2012.03/
  |...
|-src/
  |-main.cpp
|-bin/
  |-hello
|-prelink_arm.conf

的main.cpp

#include <stdio.h>
int main (int argc, char *argv[])
{
    fprintf(stdout, "hello world\n");
    return 0;
}

prelink_arm.conf

-l arm-2012.03/arm-none-linux-gnueabi/libc/lib 
-h arm-2012.03/arm-none-linux-gnueabi/libc/lib 
-l arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib
-h arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib

编译

arm-2012.03/bin/arm-none-linux-gnueabi-gcc -Wall -o bin_arm/hello src/main.cpp

预链接

PATH=/usr/local/sbin prelink --verbose --cache-file=cache/prelink_arm.cache --config-file=prelink_arm.conf --ld-library-path="arm-2012.03/arm-none-linux-gnueabi/libc/lib;arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib;" -h bin_arm/hello

错误消息

prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/getent: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/POSIX_V6_ILP32_OFFBIG: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/iconv: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/sprof: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/iconvconfig: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/POSIX_V7_ILP32_OFF32: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/zdump: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/pcprofiledump: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/gencat: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/gdbserver: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/pldd: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/locale: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/localedef: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/XBS5_ILP32_OFFBIG: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/zic: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/POSIX_V7_ILP32_OFFBIG: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/rpcgen: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/makedb: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/getconf: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/XBS5_ILP32_OFF32: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/POSIX_V6_ILP32_OFF32: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: bin_arm/hello: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'

如果我将可执行文件所依赖的所有库提取到一个单独的文件夹中并相应地设置链接,那么我仍然会收到以下错误:

prelink: bin_arm/hello: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'

2 个答案:

答案 0 :(得分:1)

是的,我找到了解决方案:

我必须指定 sysroot 并明确告诉prelink要预编译哪些库。

目录结构现在如下所示:

|- arm-2012.03/arm-none-linux-gnueabi/libc/usr/local/bin/hello
  \- /arm-none-linux-gnueabi
    \- libc
      \- lib
        \- libc-2.15.so
        |- libgcc_s.so.1
        |- ld-2.15.so
        |- ...
      |- usr
        \- local
          \- bin
            \- hello
      |- etc
        \- prelink.conf
|- Makefile

<强> prelink.conf

-l /libc/lib
-h /libc/lib

这是prelink命令:

PATH=/usr/local/sbin prelink --verbose --root=arm-2012.03/arm-none-linux-gnueabi/libc/ --cache-file=/etc/cache/prelink.cache --config-file=/etc/prelink.conf --ld-library-path="/lib;" -h /usr/local/bin/hello /lib/libc-2.15.so /lib/libgcc_s.so.1 /lib/ld-2.15.so

源代码可以在github上找到,请务必查看分支'master'和'shared-library':https://github.com/fnbk/prelink-cross-example

答案 1 :(得分:0)

我想你必须使用:
lib文件夹的完整路径:

<强> prelink_arm.conf

-l arm-2012.03/arm-none-linux-gnueabi/libc/lib     
-h arm-2012.03/arm-none-linux-gnueabi/libc/lib     
-l arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib  
-h arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib  

此处+将PATH添加到PATH变量:
预关联

PATH=/usr/local/sbin:$PATH prelink --verbose  \
--cache-file=cache/prelink_arm.cache --config-file=prelink_arm.conf \
--ld-library-path="arm-2012.03/arm-none-linux-gnueabi/libc/lib;arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib;" \
-h bin_arm/hello

实际上所有这些错误都指向你:

  

加载共享库时无法解析/ usr / local / sbin // prelink-rtld:错误:ld-linux.so.3

如果前两个音符无效,您可以尝试:

  • 查找/下载ld-linux.so.3
  • 设置export LD_LIBRARY_PATH=$PATH_TO_LD_LINUX_SO_3:$LD_LIBRARY_PATH
  • 或使用--ld-library-path=选项添加它,就像已经为其他库
  • 所做的那样

它会为您的环境添加自定义搜索路径。