您的位置:首页 > 运维架构 > Linux

[arm-linux]交叉编译ghostscript

2014-04-14 19:03 507 查看
编译器:arm-linux-gcc 3.4.1

ghostscript是一个格式转换软件,可以将PostScript语言文件(.ps)及pdf文件转换成各种格式,本文为了实现在嵌入式系统中将上述文件转换为pbmraw文件供hp1020激光打印机使用,特研究了ghostscript软件在arm-linux平台下的交叉编译。

笔者一共下载了三个版本的ghostscript软件,分别为8.70、8.53、8.15,应该都可以通过交叉编译,但考虑到嵌入式系统资源有限,最终选择8.15版本,交叉编译后的gs程序为2.6MB(8.53为3.0MB,8.70更大)。

(一)交叉编译流程:

(1)解压ghostscript-8.15,改目录名称为ghostscript-8.15-x86,运行./configure后直接make,编译出x86版本

(2)解压ghostscript-8.15,运行./configure --host=arm-linux,然后执行make

(3)错误1:

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

./obj/echogs: ./obj/echogs: cannot execute binary file

原因:编译ghostscript过程中需要使用三个中间应用程序,也被编译成arm-linux格式,主机不识别

解决方法:复制ghostscript-8.15-x86/obj目录下的echogs、genarch、genconf三个可执行程序到ghostscript-8.15/obj目录下

(4)错误2:

/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/bin/ld: skipping incompatible /usr/lib/libXt.so when searching for -lXt

/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/bin/ld: cannot find -lXt

collect2: ld returned 1 exit status

make: *** [bin/gs] 错误 1

原因:x11相关的内容,可能arm-linux不支持

解决方法:修改ghostscript-8.15下Makefile文件,注释掉以下和x11相关内容

#DEVICE_DEVS=$(DISPLAY_DEV) $(DD)x11.dev $(DD)x11alpha.dev $(DD)x11cmyk.dev $(DD)x11gray2.dev $(DD)x11gray4.dev $(DD)x11mono.dev

(5)至此顺利编译生成/bin/gs文件

(二)ghostscript在arm平台上的使用j

(1)运行./gs -h可以查看ghostscript帮助:

/ # ./gs -h

GPL Ghostscript 8.15 (2004-09-22)

Copyright (C) 2004 artofcode LLC, Benicia, CA. All rights reserved.

Usage: gs [switches] [file1.ps file2.ps ...]

Most frequently used switches: (you can use # in place of =)

-dNOPAUSE no pause after page | -q `quiet', fewer messages

-g<width>x<height> page size in pixels | -r<res> pixels/inch resolution

-sDEVICE=<devname> select device | -dBATCH exit after last file

-sOutputFile=<file> select output file: - for stdout, |command for pipe,

embed %d or %ld for page #

Input formats: PostScript PostScriptLevel1 PostScriptLevel2 PostScriptLevel3 PDF

Default output device: bmpmono

Available devices:

bbox bit bitcmyk bitrgb bj10e bj200 bjc600 bjc800 bmp16 bmp16m bmp256

bmp32b bmpgray bmpmono bmpsep1 bmpsep8 cdeskjet cdj550 cdjcolor cdjmono

cljet5 cljet5c deskjet devicen djet500 epswrite faxg3 faxg32d faxg4 ijs

jpeg jpeggray laserjet lj5gray lj5mono ljet2p ljet3 ljet3d ljet4 ljet4d

ljetplus nullpage pbm pbmraw pcx16 pcx24b pcx256 pcxcmyk pcxgray pcxmono

pdfwrite pgm pgmraw pgnm pgnmraw pj pjxl pjxl300 pkm pkmraw pksm pksmraw

png16 png16m png256 pngalpha pnggray pngmono pnm pnmraw ppm ppmraw

psdcmyk psdrgb psgray psmono psrgb pswrite pxlcolor pxlmono spotcmyk

tiff12nc tiff24nc tiffcrle tiffg3 tiffg32d tiffg4 tifflzw tiffpack

uniprint xcf

Search path:

. : /usr/local/share/ghostscript/8.15/lib :

/usr/local/share/ghostscript/8.15/Resource :

/usr/local/share/ghostscript/fonts

For more information, see /usr/local/share/ghostscript/8.15/doc/Use.htm.

Report bugs to , using the form in Bug-form.htm.

可见还需要lib、Resource和fonts目录,将ghostscript-8.15目录中的相应lib和Resource拷贝至对应位置。

至于fonts目录,可以先从主机的urs/local/share目录中拷贝过来。

(2)运行gs转换ps或pdf文件

./gs -q -dBATCH -dSAFER -dQUIET -dNOPAUSE -sPAPERSIZE=a4 -r300x300 -sDEVICE=pbmraw -sOutputFile=test.pbm test.ps

我们需要使用gs将ps文件转换为pbmraw格式,命令如上,但是转换中提示错误:

/ # ./gs -q -dBATCH -dSAFER -dQUIET -dNOPAUSE -sPAPERSIZE=a4 -r300x300 -sDEVICE=pbmraw -sOutputFile=test2.pbm chess.ps

Error: /invalidfont in findfont

Operand stack:

F1 12 Times-Roman Font Times-Roman 287289 Times-Roman --nostringval-- Times-Roman NimbusRomNo9L-Regu Courier NimbusMonL-Regu

Execution stack:

%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1 3 %oparray_pop 1 3 %oparray_pop 1 3 %oparray_pop 1
3 %oparray_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- 3 4 %oparray_pop 4 4 %oparray_pop --nostringval-- --nostringval-- --nostringval-- --nostringval--
--nostringval-- false 1 %stopped_push 7 5 %oparray_pop --nostringval-- --nostringval-- --nostringval-- 1 -1 1 --nostringval-- %for_neg_int_continue

Dictionary stack:

--dict:1118/1686(ro)(G)-- --dict:0/20(G)-- --dict:75/200(L)-- --dict:31/70(L)-- --dict:17/17(ro)(G)-- --dict:1118/1686(ro)(G)--

Current allocation mode is local

Last OS error: 2

Current file position is 61042

GPL Ghostscript 8.15: Unrecoverable error, exit code 1

错误原因:/invalidfont in findfont,没找到相应的字体

解决方法:看来chess.ps这个文件需要Times-Roman字体,不用搜索了,系统中不叫这个名字,需要查看lib目录中的fontmap.gs文件

line170 /Times-Roman /NimbusRomNo9L-Regu;

line122 /NimbusRomNo9L-Regu (n021003l.pfb) ;

原来Times-Roman字体对应的文件是n021003l.pfb,刚刚复制的fonts目录肯定有这个文件,但是被分散在子目录中,将这个文件复制到fonts根目录即可。

pdf文件需要的字体可能还不一样,请自行尝试,gs附带的参数也可以修改。

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