您的位置:首页 > 移动开发 > Android开发

Android 上移植 Ghostscript 9.04 静态编译

2012-03-04 18:29 281 查看
、说明

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

命令:

1
$
tar
zxvf
ghostscript-9.04.
tar
.gz
2
$
cp
ghostscript-9.04
ghostscript-9.04-pc -R
3
$
mv
ghostscript-9.04
ghostscript-9.04-arm
2.编译PC主机上的gs

命令:

1
$
cd
ghostscript-9.04-pc/
2
$./configure
3
$
make
这样就编译出了PC机上的gs,后面交叉编译时需要用到这一步编译出的中间文件,在./obj/aux/目录。

3.编译arm-linux上的gs

配置环境变量:

在环境变量PATH中添加交叉编译工具链的路径(arm-linux-gcc的路径)。

命令:

1
$
export
PATH=$PATH:/toolschain/4.5.1/bin
开始编译:

这里的./configure命令需要与PC主机上的不同。

命令:

1
$
cd
../
ghostscript-9.04-arm/
2
$./configure
--host=arm-linux
3
$
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/

命令:

1
$
cp
../ghostscript-9.04-pc/obj/aux/echogs
./obj/aux/echogs
2
$
cp
../ghostscript-9.04-pc/obj/aux/genarch
./obj/aux/genarch
3
$
cp
../ghostscript-9.04-pc/obj/aux/genconf
./obj/aux/genconf
4
$
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需要更新修改时间, 否则它会被重新创建

命令:

1
$
cp
../ghostscript-9.04-pc/obj/aux/mkromfs
./obj/aux/mkromfs
2
$
touch
./obj/aux/mkromfs
3
$
make
编译完成,但是并没有静态编译,这样不能在Android下运行。主要是最后链接时没有使用-static。

找到./base/unixlink.mak,这个文件最后一部分用于最后链接。

将56行

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

改为

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

命令:

1
$
rm
bin/gs
2
$/bin/sh
<./obj/ldt.
tr
编译成功,可以下载到开发板上试试了

三、对移植ghostscript-9.04过程的改进

1
$
tar
zxvf
ghostscript-9.04.
tar
.gz
2
$
cd
ghostscript-9.04
3
$./configure
--host=arm-linux
修改Makefile:

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

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

#make
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: