Android 上移植 ghostscript-9.04 静态编译

一、说明

因为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-pcghostscript-9.04-arm两分,分别用于编译PC主机上的gsarm-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

出错原因:

编译过程需要一些中间文件(echogsgenarchgenconfmkromfs),这些文件在这里被编译成了arm-linux的,要在PC主机上运行者些文件是不行的,只好从ghostscript-9.04-pc/obj/aux/拷贝过来。

解决方法:

ghostscript-9.04-pc/obj/aux/的三个文件echogsgenarchgenconf拷贝到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-gccCCAUX=gcc

#make

比上步省事多了吧。


更多相关文章

  1. Android 文件系统移植
  2. android studio修改配置文件(.android .gradle .AndroidStudio)
  3. Android NDK系列(三)-AS编写C文件没有提示和不识别NULL
  4. android 用命令行打包生成 apk
  5. Android开发之文件下载
  6. 解决android中使用shape文件画虚线不显示
  7. [置顶] Android常用命令
  8. 如何设置Android命令行环境变量
  9. AndroidManifest.xml文件剖析 (二)

随机推荐

  1. 后台九 文章列表
  2. 4.0 Ansible Playbook复用
  3. 你只知大数据的便利,却不知漏洞——hadoop
  4. 你凭什么说Spring会导致MyBatis的一级缓
  5. Spring Boot 应用监控,早发现早
  6. 漫谈Android组件化及Web化
  7. 从微软Azure云设计模式来看云化及下一代
  8. 一键生成前后端代码,Mybatis-Plus代码生成
  9. DolphinDB数据导入教程
  10. 练习2-9 整数四则运算 (10分)