James Bryant

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

0
阅读(1446)

最近一直在完善基于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: https://yunpan.cn/cMkkk9pDiuu7G (提取码:2488)

        htop-1.0.2:  https://yunpan.cn/cMkknBsW6T5kp (提取码:b16f)

  2、编译前准备

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

tar xvzf ncurses.tar.gz

tart xvzf htop-1.0.2.tar.gz

mkdir install_ncurses

mkdir 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_ncurses

cp -frP lib/* /mnt/sysroot/usr/lib/

cp -frP share/* /mnt/sysroot/usr/share/

cd /home/liangwode/test/install_htop

cp -P bin/htop /mnt/sysroot/usr/sbin/

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

 

htop

1  [##                                                                                          1.3%]     Tasks: 13, 0 thr; 1 running

2  [#******                                                                                     6.4%]     Load average: 0.15 0.11 0.10

3  [###******                                                                                   8.8%]     Uptime: 03:41:00

4  [*                                                                                           0.6%]

Mem[|||||||||||||||||#*                                                                    167/997MB]

Swp[                                                                                           0/0MB]

PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command                                                                                                                                            

10619 root       20   0  2964  1920  1540 R  6.9  0.2  0:01.43 htop                                                                                                                                               

1514 root       20   0  2828  1772  1516 S  6.3  0.2 12:41.46 htop

241 root       20   0  2592  1368  1284 S  0.6  0.1  1:00.63 /bin/sh /etc/init.d/led_run

10583 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 init

252 root       20   0  2104  1276  1180 S  0.0  0.1  0:00.01 /usr/sbin/dropbear

259 root       20   0  2592  1112  1032 S  0.0  0.1  0:00.00 /usr/sbin/telnetd

264 root       20   0  2592  1284  1204 S  0.0  0.1  0:00.00 /usr/sbin/inetd

268 root       20   0  2596  1460  1348 S  0.0  0.1  0:00.17 -sh

294 root       20   0  4508  3484  3128 S  0.0  0.3  0:00.52 wpa_supplicant -iwlan0 -Dnl80211 -c/etc/wpa_supplicant.conf -qq

367 root       20   0  2592   748   656 S  0.0  0.1  0:00.00 udhcpc -i wlan0 -S

10605 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版本后成功编译。