天天看點

linux交叉編譯生成的是什麼,靜态連結util-linux – 交叉編譯(生成動态連結檔案)...

我一直試圖交叉編譯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