Android 上移植 Ghostscript 9.04 静态编译

来源:LinuxIDC.com 作者:LinuxIDC.com
  

一、说明

因为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

比上步省事多了吧。


时间:2011-10-12 21:51 来源:LinuxIDC.com 作者:LinuxIDC.com 原文链接

好文,顶一下
(1)
100%
文章真差,踩一下
(0)
0%
------分隔线----------------------------


把开源带在你的身边-精美linux小纪念品
无觅相关文章插件,快速提升流量