1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 交叉编译HTOP并移植到ARM嵌入式Linux系统

交叉编译HTOP并移植到ARM嵌入式Linux系统

时间:2020-06-21 05:17:13

相关推荐

交叉编译HTOP并移植到ARM嵌入式Linux系统

原创作品,允许转载,转载时请务必以超链接形式标明文章、作者信息和本声明,否则将追究法律责任。

最近一直在完善基于Busybox做的ARM Linux的根文件系统,由于busybox是一个精简的指令集组成的简单文件系统,其优点就是极精简,满足了Linux基本的启动需求,由于它几乎没有什么后台服务,对于追求极度裁剪的系统开发者而言是一个非常好的体验,不过,也正是由于其精简,很多我们在开发测试中使用的工具或者库也可能都没有,这对于开发者而言也增加了一定的移植工作量,笔者最近正被各种移植工具软件和库文件深深折磨着,今天主要说一下一个比较实用的工具HTOP的移植过程。

htop是什么

htop——一个可以让用户与之交互的进程查看器。作为文本模式的应用程序,主要用于控制台或X终端中。当前具有按树状方式来查看进程,支持颜色主题,可以定制等特性。

与top相比,htop有以下优点:

1、可以横向或纵向滚动浏览进程列表,以便看到所有的进程和完整的命令行。

2、在启动上,比 top 更快。

3、杀进程时不需要输入进程号。

4、htop 支持鼠标操作。

5、top 已经很老了。

htop移植

1、编译环境

Host机:ubuntu-16.10(64bit)

Target:arm

交叉工具链:arm-linux-gnueabi-gcc

工具包:

ncurses-5.9.7:/cMkkk9pDiuu7G (提取码:2488)

htop-1.0.2:/cMkknBsW6T5kp (提取码:b16f)

2、编译前准备

下载两个压缩包,放在/home/liangwode/test目录下,解压缩两个压缩文件夹,并创建编译安装目录。

tar xvzf ncurses.tar.gztart xvzf htop-1.0.2.tar.gzmkdir install_ncursesmkdir install_htop

3、编译ncurses

由于htop依赖于ncurses库,因此需要先编译ncurses,进入ncurses目录,并配置交叉编译

cd ncurses-5.9./configure --prefix=/home/test/install_ncurses --host=arm-linux-gnueabi --without-cxx --without-cxx-binding --without-ada --without-manpages --without-progs --without-tests --with-shared

编译并安装ncurses库

make && make install

这样在/home/test/install_ncurses目录下就生成了ncurses的库和头文件等文件

bin include lib share

4、编译htop

进入htop目录,并配置htop交叉编译选项,注意需通过LDFLAGS指定ncurses库所在的目录并通过CPPFLAGS指定ncurses头文件所在的目录

cd htop-1.0.2./configure --prefix=/home/liangwode/test/install_htop --disable-unicode --host=arm-linux-gnueabi LDFLAGS=-L/home/liangwode/test/install_ncurses/lib CPPFLAGS=-I/home/liangwode/test/install_ncurses/include/ncurses

编译并安装htop

make && make install

完可成后可以在在/home/liangwode/test/install_htop目录下生成安装完文件。

5、移植到目标机文件系统

将ncurses编译生成的文件及htop的可执行文件移植到目标系统对应的文件夹,笔者根文件系统在sd卡,已经挂载到了/mnt/sysroot目录下

cd /home/liangwode/test/install_ncursescp -frP lib/* /mnt/sysroot/usr/lib/cp -frP share/* /mnt/sysroot/usr/share/cd /home/liangwode/test/install_htopcp -P bin/htop /mnt/sysroot/usr/sbin/

OK,将sd卡插入目标机,重启目标机系统,进入系统后,htop可用:

htop1 [##1.3%]Tasks: 13, 0 thr; 1 running2 [#******6.4%]Load average: 0.15 0.11 0.10 3 [###****** 8.8%]Uptime: 03:41:004 [* 0.6%]Mem[|||||||||||||||||#* 167/997MB]Swp[ 0/0MB]PID USERPRI NI VIRT RES SHR S CPU% MEM% TIME+ Command 10619 root 20 0 2964 1920 1540 R 6.9 0.2 0:01.43 htop1514 root 20 0 2828 1772 1516 S 6.3 0.2 12:41.46 htop241 root 20 0 2592 1368 1284 S 0.6 0.1 1:00.63 /bin/sh /etc/init.d/led_run10583 root 20 0 2512 1668 1316 S 0.0 0.2 0:00.26 /usr/sbin/dropbear 1 root 20 0 2592 1380 1292 S 0.0 0.1 0:02.97 init252 root 20 0 2104 1276 1180 S 0.0 0.1 0:00.01 /usr/sbin/dropbear259 root 20 0 2592 1112 1032 S 0.0 0.1 0:00.00 /usr/sbin/telnetd264 root 20 0 2592 1284 1204 S 0.0 0.1 0:00.00 /usr/sbin/inetd268 root 20 0 2596 1460 1348 S 0.0 0.1 0:00.17 -sh294 root 20 0 4508 3484 3128 S 0.0 0.3 0:00.52 wpa_supplicant -iwlan0 -Dnl80211 -c/etc/wpa_supplicant.conf -qq367 root 20 0 2592 748 656 S 0.0 0.1 0:00.00 udhcpc -i wlan0 -S10605 root 20 0 2596 1528 1432 S 0.0 0.1 0:00.03 -sh

后记:

在编译的过程中,笔者测试了htop-2.0.0,htop-2.0.2版本,可能是和ncurses版本不匹配的原因,按照同样的方法编译总是失败,错误要么是找不到ncurses的库,要么找不到ncurses的头文件,最后只能放弃,选择了htop-1.0.2版本后成功编译。

备注:

如果编译ncurse报错:

gcc -DHAVE_CONFIG_H -I. -I../include -D_GNU_SOURCE -DNDEBUG -O2 --param max-inline-insns-single=1200 -c ../ncurses/lib_gen.c -o ../objects/lib_gen.o

In file included from ./curses.priv.h:325:0,

from ../ncurses/lib_gen.c:19:

_18018.c:843:15: error: expected ‘)’ before ‘int’

../include/curses.h:1631:56: note: in definition of macro ‘mouse_trafo’

#define mouse_trafo(y,x,to_screen) wmouse_trafo(stdscr,y,x,to_screen)

^

Makefile:967: recipe for target '../objects/lib_gen.o' failed

make[1]: *** [../objects/lib_gen.o] Error 1

make[1]: Leaving directory '/home/abuu/project/ncurses-6.0/ncurses'

Makefile:113: recipe for target 'all' failed

make: *** [all] Error 2

请删除删除include/curses.h中mouse_trafo所在行的注释(/*generated*/),重新make,顺利编译通过

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。