htop的编译

嵌入式系统busybox自带的top工具,一般都是裁剪版;在业务中排查一些CPU占有率高、内存占用等问题,就可能需要htop来帮忙了。htop的编译过程也是波折,因此记录下来作为总结。

htop资源:http://hisham.hm/htop/releases/1.0.1/htop-1.0.1.tar.gz
ncurses-5.9资源:http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz

1、ncurses-5.9
./configure --prefix=/work/tools/ncu_install --host=arm-linux- --without-cxx --without-cxx-binding --without-ada --without-manpages --without-progs --without-tests --with-shared

编译ncurses是编译linux内核时用到的一个工具,在make时遇到了如下错误:
In file included from …/ncurses/curses.priv.h:283:0,
from …/ncurses/lib_gen.c:19:
_46863.c:835:15: error: expected ‘)’ before ‘int’
…/include/curses.h:1594:56: note: in definition of macro ‘mouse_trafo’
#define mouse_trafo(y,x,to_screen) wmouse_trafo(stdscr,y,x,to_screen) ^
Makefile:790: recipe for target ‘…/objects/lib_gen.o’ failed
make[1]: *** […/objects/lib_gen.o] Error 1
make[1]: Leaving directory ‘/home/ran/workspace/ncurses-5.9/ncurses’
Makefile:109: recipe for target ‘all’ failed
make: *** [all] Error 2

根据出错提示,找到ncurses目录下,include文件夹里的curses.h文件,查找mouse_trafo,锁定在1584行:
1583 extern NCURSES_EXPORT(bool) wmouse_trafo (const WINDOW*, int*, int*, bool);
1584 extern NCURSES_EXPORT(bool) mouse_trafo (int*, int*, bool); /* generated */

应该是由后面的一行注释引起的,具体原因不详。
由于代码的部分是由另一个文件curses.tail导入的,所以要修改curses.tail:
sudo vim curses.tail

查找mouse_trafo,定位到104行,去除104行后面的注释:
103 extern NCURSES_EXPORT(bool) wmouse_trafo (const WINDOW*, int*, int*, bool);
104 extern NCURSES_EXPORT(bool) mouse_trafo (int*, int*, bool); /* generated */

保存后退出,重新make即可。

2、htop
./configure --prefix=/work/tools/htop_install --disable-unicode --host=arm-linux LDFLAGS=-L/work/tools/ncu_install/lib CPPFLAGS=“-I/work/tools/ncu_install/include/ -I/work/tools/ncu_install/include/ncurses” CC=arm-linux-gcc

终端显示的内容如下:

checking if compiler supports -Wextra… yes
checking for refresh in -lncurses… no
checking for refresh in -lncurses6… no
checking for refresh in -lncurses… (cached) no
checking curses.h usability… yes
checking curses.h presence… yes
checking for curses.h… yes
checking for python… python
configure: error: missing libraries: libncurses
最后只好看config.log文件了,发现里面有个奇怪的问题,提示缺少libtinfo库,和libcurses
进入ncu_install/lib目录,创建littinfo的符号链接
cd lib
ln -s libncurses.so.5 libtinfo.so.5
ln -s libtinfo.so.5 libtinfo.so
直接make && make install即可

3、测试
将ncu_install及htop_install相关成功物拷贝到设备中,配置环境变量:
ln -s ${PWD}/share/terminfo/ /usr/share
export TERMINFO=/usr/share/terminfo

htop测试OK

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值