我一直试图交叉编译util-linux for arm但我一直以动态链接的可执行文件结束,我不知道为什么会这样.我的目标是静态的.我在使用类似步骤的不同工具之前进行了交叉编译,并且它一直有效,所以这次我不知道我做错了什么.我正在使用Ubuntu 16.04.以下是我正在运行的命令:
export CC=arm-linux-gnueabi-gcc
export ac_cs_linux_vers=4
export CFLAGS=-static
export CPPFLAGS=-static
export LDFLAGS=-static
./configure --host=arm-linux LDFLAGS=-static --disable-shared --without-tinfo --without-ncurses --disable-ipv6 --disable-pylibmount --enable-static-programs=fdisk,sfdisk,whereis --prefix=/opt/util-linux/arm --bindir=/opt/util-linux/arm/bin --sbindir=/opt/util-linux/arm/sbin
正如你所看到的,我在每个我能想到的地方指定静态甚至重复“只是为了确保它理解我”并且在我运行configure脚本之后,这里是输出:
util-linux 2.28.2
prefix: /opt/util-linux/arm
exec prefix: ${prefix}
localstatedir: ${prefix}/var
bindir: /opt/util-linux/arm/bin
sbindir: /opt/util-linux/arm/sbin
libdir: ${exec_prefix}/lib
includedir: ${prefix}/include
usrbin_execdir: ${exec_prefix}/bin
usrsbin_execdir: ${exec_prefix}/sbin
usrlib_execdir: ${exec_prefix}/lib
compiler: arm-linux-gnueabi-gcc
cflags: -static
suid cflags:
ldflags: -static
suid ldflags:
Python: /usr/bin/python
Python version: 2.7
Python libs: ${exec_prefix}/lib/python2.7/site-packages
Bash completions: /usr/share/bash-completion/completions
Systemd support: no
Btrfs support: yes
warnings:
然后我做:
make fdisk
要么
make whereis
编译完成后,我做:
file fdisk
fdisk是刚刚创建的文件,并且:
fdisk: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=369363ef8f8173a3a1c2edc178eb77255a2dc415, not stripped
正如你所看到的那样,“动态链接”.我一直在互联网上搜索,但我没有找到答案.我也这样做:
./configure --host=arm-linux LDFLAGS=-static --disable-shared --without-tinfo --without-ncurses --disable-ipv6 --disable-pylibmount --prefix=/opt/util-linux/arm --bindir=/opt/util-linux/arm/bin --sbindir=/opt/util-linux/arm/sbin
这与之前的配置命令完全相同,除了缺少“–enable-static-programs”参数,“默认情况下应该”将所有内容编译为静态,除非它没有.
我做错了什么或这是一个Makefile错误?
解决方法:
静态二进制文件使用.static扩展构建;在构建之后,我得到了
$file fdisk.static
fdisk.static: ELF 32-bit LSB executable, ARM, EABI5 version 1 (GNU/Linux), statically linked, for GNU/Linux 3.2.0, BuildID[sha1]=b51ec4b17f772b881d2a1eaefd368cfb96d0db12, not stripped
我只有这个
./configure --host=arm-linux-gnueabihf --enable-static-programs=fdisk
(你不需要任何FLAGS变量;在你的设置中用gnueabi替换gnueabihf,我只是用它,因为我已经有了一个工作的armhf交叉编译设置).
标签:linux,arm
来源: https://codeday.me/bug/20190814/1652743.html