摘要:在linux開發過程當中常常須要用到第三方的程序,有時須要用到它們的庫,有時須要它們生成的可執行文件,如何正確地編譯這些第三方的程序,以方便地使用和開發本身須要的程序,將是本文要論述的內容.php
1.移植第三方程序有幾種狀況linux
1.1 若是源碼包有Makefile文件,直接改Makefile,修改CC, AS, LD, CFLAGS,INSTALL_PATH等。vim
1.2 源碼包沒有Makefile文件,但有configure/config文件:服務器
1.2.1設置 CC, LD ,AS, LDFLAGS ,AR,RANLIB等環境變量,以下面的lrzsz命令移植中的測試
CC=/opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-gcc AR=/opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-ar LD=/opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-ld AS=/opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-as RANLIB=/opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-ranlib ./configure --host=arm-linuxui
指定交叉編譯器路徑,指定連接路徑及AS,AR等。spa
1.2.2 make .net
1.2.3.make install3d
1.3 沒有configure/config,也沒有Makefile,可是會有一個autogen.sh腳本unix
1.3.1sh autogen.sh -->生成configure文件
1.3.2 再按照二作。
2.下面以移植lrzsz爲例進行講解:
2.1從網上下載lrzsz壓縮包(http://download.chinaunix.net/download.php?ResourceID=6293&id=12772)
[weishusheng@localhost thirdparty]$ ls
lrzsz-0.12.20.tar.gz
2.2.解壓
[weishusheng@localhost thirdparty]$ tar -xzf lrzsz-0.12.20.tar.gz
[weishusheng@localhost thirdparty]$ ls
lrzsz-0.12.20 lrzsz-0.12.20.tar.gz
2.3.進入lrzsz-0.12.20
2.4.生成Makefile文件
[weishusheng@localhost lrzsz-0.12.20]$ CC=/opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-gcc AR=/opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-ar LD=/opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-ld AS=/opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-as RANLIB=/opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-ranlib ./configure --host=arm-linux
2.5.
2.6.[weishusheng@localhost lrzsz-0.12.20]$ make
2.7.
2.8.咱們看到lsz與lrz是在arm上運行的
2.9.把lsz,lrz下到開發板
先放到、tftp目錄下
[weishusheng@localhost src]$ cp lsz lrz /tftp
在開發板上下載
>: tftp -gr lsz 192.168.1.3
>: tftp -gr lrz 192.168.1.3
修改權限
>: chmod 777 lsz lrz
2.10.測試
移植第三方程序lszrz成功。
3 tree程序移植到fl2440開發板
3.1.第一步一樣從網上下載壓縮包
3.2.解壓
[weishusheng@localhost tree]$ tar -xzf tree-1.5.1.tar.gz
[weishusheng@localhost tree]$ ls
tree-1.5.1 tree-1.5.1.tar.gz
3.3.[weishusheng@localhost tree]$ cd tree-1.5.1
3.4.修改相關設置
[weishusheng@localhost tree-1.5.1]$ sudo vim Makefile
把CC=gcc
改成
CC=/opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-gcc
3.5.編譯
[weishusheng@localhost tree-1.5.1]$ sudo make
3.6.上傳到tftp服務器
[weishusheng@localhost tree-1.5.1]$ sudo cp tree /tftp
3.7.下載到開發板
3.8.測試
tree命令移植到fl2440開發板成功。