我正在尝试 cross-prelink 一个简单的 hello world 程序。我使用交叉编译工具链 arm-2012.03-57-arm-none-linux-gnueabi-i686-pc-linux-gnu,我不确定我是否正确使用了 prelink-cross 选项。如果有人能指出我正确的方向,我会很高兴。有关 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'
最佳答案
是的,我找到了解决方案:
我必须指定 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
这是预链接命令:
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 上找到,请确保 checkout 两个分支“master”和“shared-library”:https://github.com/fnbk/prelink-cross-example