交叉編譯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: 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版本后成功編譯。  

 

備注:

  如果編譯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,順利編譯通過


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM