歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android 上移植 Ghostscript 9.04 靜態編譯

Android 上移植 Ghostscript 9.04 靜態編譯

日期:2017/3/1 11:12:54   编辑:Linux編程

一、說明

因為Android沒有glib庫,而gcc默認為動態編譯,為了使程序能在開發板上運行,我們自己的C程序需要采用靜態編譯。

ghostscript的下載地址為http://downloads.ghostscript.com/public/。我用的是ghostscript-9.04。

二、網上常見的方法

1.獲取源代碼

解壓ghostscript-9.04.tar.gz ,並將解壓後的ghostscript-9.04目錄拷貝成ghostscript-9.04-pc和ghostscript-9.04-arm兩分,分別用於編譯PC主機上的gs和arm-linux上的gs。

命令:

#tarzxvf ghostscript-9.04.tar.gz

#cpghostscript-9.04 ghostscript-9.04-pc -R

#mvghostscript-9.04 ghostscript-9.04-arm

2.編譯PC主機上的gs

命令:

#cdghostscript-9.04-pc/

#./configure

#make

這樣就編譯出了PC機上的gs,後面交叉編譯時需要用到這一步編譯出的中間文件,在./obj/aux/目錄。

3.編譯arm-linux上的gs

配置環境變量:

在環境變量PATH中添加交叉編譯工具鏈的路徑(arm-linux-gcc的路徑)。

命令:

#exportPATH=$PATH:/toolschain/4.5.1/bin

開始編譯:

這裡的./configure命令需要與PC主機上的不同。

命令:

#cd../ ghostscript-9.04-arm/

#./configure--host=arm-linux

#make

編譯過程會出現下面的錯誤

出現錯誤:

./obj/aux/echogs-w ./obj/devs.tr - -include ./obj/unix_

./obj/aux/echogs:1: Syntax error: word unexpected (expecting ")")

make:*** [obj/devs.tr] 錯誤 2

出錯原因:

編譯過程需要一些中間文件(echogs、genarch、genconf、mkromfs),這些文件在這裡被編譯成了arm-linux的,要在PC主機上運行者些文件是不行的,只好從ghostscript-9.04-pc/obj/aux/拷貝過來。

解決方法:

將ghostscript-9.04-pc/obj/aux/的三個文件echogs、genarch、genconf拷貝到ghostscript-9.04-arm/obj/aux/

命令:

#cp../ghostscript-9.04-pc/obj/aux/echogs ./obj/aux/echogs

#cp../ghostscript-9.04-pc/obj/aux/genarch ./obj/aux/genarch

#cp../ghostscript-9.04-pc/obj/aux/genconf ./obj/aux/genconf

#make

出現錯誤:

./obj/aux/mkromfs:2: Syntax error: word unexpected (expecting ")")

make:*** [obj/gsromfs1_.c] 錯誤 2

解決方法:

將ghostscript-9.04-pc/obj/aux/的文件mkromfs拷貝到ghostscript-9.04-arm/obj/aux/。注意,mkromfs需要更新修改時間, 否則它會被重新創建

命令:

#cp../ghostscript-9.04-pc/obj/aux/mkromfs ./obj/aux/mkromfs

#touch ./obj/aux/mkromfs

#make

編譯完成,但是並沒有靜態編譯,這樣不能在Android下運行。主要是最後鏈接時沒有使用-static。

找到./base/unixlink.mak,這個文件最後一部分用於最後鏈接。

將56行

$(ECHOGS_XE)-a $(ldt_tr) -s - $(EXTRALIBS) $(STDLIBS)

改為

$(ECHOGS_XE)-a $(ldt_tr) -s - $(EXTRALIBS) $(STDLIBS) -static

命令:

#rmbin/gs

#/bin/sh<./obj/ldt.tr

編譯成功,可以下載到開發板上試試了

三、我對移植ghostscript-9.04過程的改進

#tarzxvf ghostscript-9.04.tar.gz

#cd ghostscript-9.04

#./configure--host=arm-linux

修改Makefile:

320行:修改STDLIBS=-lpthread-lm 為STDLIBS=-lpthread -lm-static

387行:修改CCAUX=arm-linux-gcc為CCAUX=gcc

#make

比上步省事多了吧。

Copyright © Linux教程網 All Rights Reserved