歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 交叉編譯HTOP並移植到ARM嵌入式Linux系統

交叉編譯HTOP並移植到ARM嵌入式Linux系統

日期:2017/2/28 13:49:28   编辑: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 與 htop-1.0.2Linux公社資源站下載:

------------------------------------------分割線------------------------------------------

免費下載地址在 http://linux.linuxidc.com/

用戶名與密碼都是www.linuxidc.com

具體下載目錄在 /2016年資料/8月/29日/交叉編譯HTOP並移植到ARM嵌入式Linux系統/

下載方法見 http://www.linuxidc.com/Linux/2013-07/87684.htm

------------------------------------------分割線------------------------------------------

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版本後成功編譯。  

Copyright © Linux教程網 All Rights Reserved