交叉编译htop aarch64 版本(全网第一个)(linux开发笔记)

准备工具

开始编译

  • 第一步:先编译ncurser
#下载
wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz
#解压
tar -zxvf ncurses-5.9.tar.gz
# configure 配置
`./configure --prefix=$PWD/output CC=aarch64-linux-gnu-gcc --host=aarch64-linux-gnu --without-cxx --without-cxx-binding --without-ada --without-manpages --without-progs --without-tests --with-shared`
必须加prefix,给后续htop调用链接库的时候好引用位置,因为是交叉编译依赖,所以需要install到prefix的位置
## 编译安装
make && make install
## 如果make失败执行下面这条
sed -i "s/extern NCURSES_EXPORT(bool)    mouse_trafo (int\*, int\*, bool);.*/extern NCURSES_EXPORT(bool)    mouse_trafo (int\*, int\*, bool);/"  include/curses.h
## 这样在output目录生成一下文件
bin  include  lib  share
执行完成后会在outpub/lib目录下生成库文件,进入该目录并执行下面的命令(我的环境不执行的话编译htop会报错,说找不到libncurses)
ln -s libtinfo.so.5 libtinfo.so
ln -s libncurses.so.5 libtinfo.so.5
# 查看编译出文件结构

  • 第二步: 编译htop
## 下载
wget https://github.com/hishamhm/htop/archive/refs/tags/2.2.0.tar.gz
## 解压
tar -zxvf 2.2.0.tar.gz
## 配置
./configure --prefix=$PWD/output --host=aarch64-linux-gnu --disable-unicode LDFLAGS=-L/root/htop/ncurses-5.9/output/lib LIBS=-lncurses
## 编译
make && make install

报错解决:Invalid configuration aarch64-linux’: machine `aarch64′ not recognize

下载最新的配置文件,删除旧的config.sub和config.guess

wget -O config.guess 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD'
wget -O config.sub 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD'

如何目标机器使用:
先把output/bin下面的htop拷贝到目标机器
chmod +x htop
./htop
image
以上提示缺少动态连接库
再把构建的机器上的ncurses链接库拿过来。注意不要只拿了软连接,需要将软连接和真实的.so文件一起拷贝
image
再次运行
image
还是报错bus error

更新 debug

出现以上问题的原因, 考虑是ncurses的问题,所以考虑使用ncurses6.1的版本重新编译
http://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.1.tar.gz
步骤和上面一样
最后运行结果
image

参考资料

https://www.cnblogs.com/txsf/p/3713991.html

posted @ 2023-11-07 10:00  学不会xuebuhui  阅读(312)  评论(1编辑  收藏  举报
Language: javascript