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

MuPDF在iOS平台的编译

2011-11-24 10:37 190 查看
iOS平台虽然提供了方便的PDF渲染接口,但对于简体中文字体的支持并不完整,容易发生乱码。即使在iOS 5.0中有了一定的改善,但还是存在乱码问题。

MuPDF是一款开源的PDF阅读器,渲染效率相对较高,并且对简体中文字体的支持也很好。

官网:http://www.mupdf.com/

下载并解压缩MuPDF的源码后,打开Makerules文件,查看相关编译规则,支持平台有不少,但是没有mac编译iOS平台的规则,于是添加相关规则。

模拟器i386规则:

CC = /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2

AR = /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ar

CPP = /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/cpp

CFLAGS += -arch i386 -m32 -pipe -mdynamic-no-pic -std=c99 -Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -mmacosx-version-min=10.5 -I/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/include/
-isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk

LDFLAGS +=-arch i386 -m32 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk -Wl,-dead_strip -mmacosx-version-min=10.5

CROSSCOMPILE=yes

NOX11=yes

真机armv6规则:

CC = /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2

AR = /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar

CPP = /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp

CFLAGS += -arch armv6 -pipe -mdynamic-no-pic -std=gnu99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=4.2 -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/usr/include/libxml2
-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk

LDFLAGS += -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -miphoneos-version-min=4.2

CROSSCOMPILE=yes

NOX11=yes

真机armv7规则:

CC = /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2

AR = /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar

CPP = /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp

CFLAGS += -arch armv7 -pipe -mdynamic-no-pic -std=gnu99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=4.2 -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/usr/include/libxml2
-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk

LDFLAGS += -arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -miphoneos-version-min=4.2

CROSSCOMPILE=yes

NOX11=yes

执行make libs命令,在目录下生成*.a库文件。

在过程中遇见过一些问题:

生成库文件后,在工程中调用相关接口,提示错误:ld: symbol(s) not found

经过排查,原来犯了个小错误:

MuPDF是使用C编译器编译,但是工程使用c++编译,所以需要在引用文件添加

extern "C" {

#include <fitz.h>

#include <mupdf.h>

}

编译真机版库文件时候,提示错误:‘asm’ undeclared (first use in this function)

进过排查,编译参数设置错误,将-std=c99换成-std=gnu99就成功了。

详情可见:

What's the difference between GNU99 and C99 (Clang)?
http://stackoverflow.com/questions/5313536/whats-the-difference-between-gnu99-and-c99-clang
终于木有乱码了:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: