util-linux源码下载: git clone [email protected]: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
编译的时候报如下错误:
/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
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 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
标签:gnu,aarch64,util,--,build,linux From: https://www.cnblogs.com/wanglouxiaozi/p/17836701.html