Linux kernel 交叉编译内核工具,即使正确设置了-L,也无法找到-lelf
我正试图在我的amd64机器上为armhf交叉编译官方Debian内核的修改版本。我正在使用Debian wiki上的说明 内核本身构建得很好,但在尝试为Linux kernel 交叉编译内核工具,即使正确设置了-L,也无法找到-lelf,linux-kernel,debian,cross-compiling,ld,Linux Kernel,Debian,Cross Compiling,Ld,我正试图在我的amd64机器上为armhf交叉编译官方Debian内核的修改版本。我正在使用Debian wiki上的说明 内核本身构建得很好,但在尝试为linux kbuild包构建objtool时,我从ld得到一个错误: # make -f debian/rules.real build-kbuild KBUILD_HOSTLDFLAGS="-L/usr/lib/arm-linux-gnueabihf" [...] arm-linux-gnueabihf-gcc /usr
linux kbuild
包构建objtool
时,我从ld
得到一个错误:
# make -f debian/rules.real build-kbuild KBUILD_HOSTLDFLAGS="-L/usr/lib/arm-linux-gnueabihf"
[...]
arm-linux-gnueabihf-gcc /usr/src/linux.buster-backports/debian/build/build-tools/tools/objtool/objtool-in.o -lelf /usr/src/linux.buster-backports/debian/build/build-tools/tools/objtool/libsubcmd.a -L/usr/lib/arm-linux-gnueabihf -o /usr/src/linux.buster-backports/debian/build/build-tools/tools/objtool/objtool
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lelf
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:67: /usr/src/linux.buster-backports/debian/build/build-tools/tools/objtool/objtool] Error 1
您可以看到
make
向gcc
添加了-L/usr/lib/arm-linux-gnueabihf
标志。而且/usr/lib/arm-linux-gnueabihf
确实包含libelf
:
# ls -l /usr/lib/arm-linux-gnueabihf/libelf*
-rw-r--r-- 1 root root 67296 May 28 2019 /usr/lib/arm-linux-gnueabihf/libelf-0.176.so
lrwxrwxrwx 1 root root 15 May 28 2019 /usr/lib/arm-linux-gnueabihf/libelf.so.1 -> libelf-0.176.so
# file /usr/lib/arm-linux-gnueabihf/libelf-0.176.so
/usr/lib/arm-linux-gnueabihf/libelf-0.176.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=51d60560aa6c0538f0bf34c07e4e2bc230c00834, stripped
我像这样安装了libelf
:
dpkg --add-architecture armhf
apt-get update
apt-get install libelf1:armhf
正在使用的ld
似乎确实用于arm:
# /usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld -V
GNU ld (GNU Binutils for Debian) 2.31.1
Supported emulations:
armelf_linux_eabi
armelfb_linux_eabi
我被难住了。如何获取
ld
链接libelf
?libelf-0.176都不是so
也不是libelf.so.1
通过-lelf
选项搜索链接器。您仍然需要libelf.so
文件。可以通过以下方式创建此文件:
- 通过安装
软件包(通常,带有确切libelf-dev
的库由.so
软件包安装)。确保选择适合交叉编译的包*-dev
- 通过创建符号链接
指向您拥有的libelf.so
文件libelf-0.176.so
/usr/lib/arm-linux-gnueabihf
确实包含libelf
”——实际上它不包含libelf
库。链接-lelf
从不搜索像libelf-0.176.so
或libelf.so.1
这样的文件。您可能需要创建libelf.so
文件,该文件指向libelf-0.176.so
。啊,您说得对!我安装了libelf-dev:armhf
包,其中包括armhflibelf.so
symlink,现在它链接成功。(我已经安装了-libelf-dev:amd64
软件包,但我没有意识到-dev
软件包包含特定于arch的符号链接。)如果您想写评论作为答案,我很乐意将其标记为已解决。