aarch64-linux-gnu- 交叉编译util-linux

util-linux源码下载:  git clone git@github.com:util-linux/util-linux.git 或者 https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/

执行 git tag 查看有哪些发行版本,这里切换到v2.39.2版本:

git checkout v2.39.2

交叉编译工具链:gcc-linaro-7.2.1-2017.11-x86_64_aarch64-linux-gnu

交叉编译步骤

1. 导出交叉编译工具链环境变量

export PATH=/usr/local/gcc-linaro-7.2.1-2017.11-x86_64_aarch64-linux-gnu/bin:$PATH

这里根据你的交叉编译工具链的位置进行相应的调整,我这里是把工具链放在了/usr/local目录下了。

2. 执行autogen.sh生成configure

./autogen.sh

3. 新建build目录用来安装编译后的库和可执行程序

mkdir build

4. 执行configure生成Makefile文件

./configure --host=aarch64-linux-gnu --prefix=/root/util-linux/build
  •  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
  • --prefix=PREFIX   install architecture-independent files in PREFIX [/usr]

5. 编译

make

1. 编译的时候报如下错误:

make[3]: Entering directory '/root/util-linux/po'
: --update --no-wrap --previous --lang=ca ca.po util-linux.pot
rm -f ca.gmo && : -c --statistics --verbose -o ca.gmo ca.po
mv: cannot stat 't-ca.gmo': No such file or directory
make[3]: *** [Makefile:643: ca.gmo] Error 1
make[3]: Leaving directory '/root/util-linux/po'
make[2]: *** [Makefile:681: stamp-po] Error 2
make[2]: Leaving directory '/root/util-linux/po'
make[1]: *** [Makefile:15786: all-recursive] Error 1
make[1]: Leaving directory '/root/util-linux'
make: *** [Makefile:6695: all] Error 2

解决办法:

apt-get install gettext

注意: 即使你执行 which gettext 看到系统里已经有gettext工具了,也要执行上述安装命令进行安装,系统内自带的gettext并不中用!!!

然后再重新执行 ./configure --host=aarch64-linux-gnu --prefix=/root/util-linux/build 重新生成Makefile文件。

2. 继续执行 make 编译,出现以下错误。

/usr/local/gcc-linaro-7.2.1-2017.11-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/7.2.1/../../../../aarch64-linux-gnu/bin/ld: cannot find -ltinfo
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:7857: dmesg] Error 1
make[2]: Leaving directory '/root/util-linux'
make[1]: *** [Makefile:15786: all-recursive] Error 1
make[1]: Leaving directory '/root/util-linux'
make: *** [Makefile:6695: all] Error 2

解决办法:

在执行 configure 的时候加上 --without-tinfo 选项。

./configure --host=aarch64-linux-gnu --prefix=/root/util-linux/build --without-tinfo
make

 3. configure 执行完成,继续编译的时候又出现新的错误,如下:

In file included from /usr/include/python2.7/Python.h:8:0,
                 from libmount/python/pylibmount.h:4,
                 from libmount/python/context.c:21:
/usr/include/python2.7/pyconfig.h:12:12: fatal error: aarch64-linux-gnu/python2.7/pyconfig.h: No such file or directory
 #  include <aarch64-linux-gnu/python2.7/pyconfig.h>
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

解决办法:

在执行 configure 的时候加上  --disable-pylibmount 选项。

./configure --host=aarch64-linux-gnu --prefix=/root/util-linux/build --without-tinfo --disable-pylibmount
make

静静等待编译完成。编译完成后执行 make install 进行安装,安装完成后在build目录下有如下内容:

# ls build/*
build/bin:
cal    col     dmesg      fincore  hardlink  ipcrm    last     logger  lsfd     lslogins  mesg        nsenter  renice      scriptreplay  uclampset  utmpdump   wdctl
chmem  colcrt  eject      findmnt  hexdump   ipcs     lastb    look    lsipc    lsmem     mount       pipesz   rev         setarch       umount     uuidgen    whereis
choom  colrm   fadvise    flock    ionice    isosize  linux32  lsblk   lsirq    lsns      mountpoint  prlimit  script      setsid        uname26    uuidparse
chrt   column  fallocate  getopt   ipcmk     kill     linux64  lscpu   lslocks  mcookie   namei       rename   scriptlive  taskset       unshare    wall

build/include:
blkid  libfdisk  libmount  libsmartcols  uuid

build/lib:
libblkid.a   libblkid.so.1      libfdisk.la    libfdisk.so.1.1.0  libmount.so        libsmartcols.a   libsmartcols.so.1      libuuid.la    libuuid.so.1.3.0
libblkid.la  libblkid.so.1.1.0  libfdisk.so    libmount.a         libmount.so.1      libsmartcols.la  libsmartcols.so.1.1.0  libuuid.so    pkgconfig
libblkid.so  libfdisk.a         libfdisk.so.1  libmount.la        libmount.so.1.1.0  libsmartcols.so  libuuid.a              libuuid.so.1

build/sbin:
addpart     blkid     chcpu       fdisk   fsck.minix  hwclock   mkfs        mkswap   pivot_root   resizepart  sfdisk     swapoff      uuidd
agetty      blkzone   ctrlaltdel  findfs  fsfreeze    ldattach  mkfs.bfs    nologin  raw          rfkill      sulogin    swapon       wipefs
blkdiscard  blockdev  delpart     fsck    fstrim      losetup   mkfs.minix  partx    readprofile  rtcwake     swaplabel  switch_root  zramctl

build/share:
doc  locale

 

posted @ 2023-11-16 16:46  闹闹爸爸  阅读(666)  评论(0编辑  收藏  举报