poppler交叉编译

  公司某嵌入式设备使用Qt5.5开发,需要有显示pdf文档的功能,此版本的Qt自身不支持pdf的解决方案(Qt wiki中有提到pdf的处理实现:Handling PDF)。通过比较觉得poppler比较适合,下面是交叉编译的过程。

环境

硬件环境:iMX6
交叉编译工具链:arm-poky-linux-gnueabi
gcc版本为 4.6.2
软件环境:Linux+Qt5.5.1
宿主机系统:Ubuntu18.04
poppler版本:poppler-0.67.0

编译

下载源码

  首先从官网下载源码或者通过git得到源码
git clone https://anongit.freedesktop.org/git/poppler/poppler.git

构建工具

  configure实现,但是官方的源码包里用的是cmake构建工具。如果主机没有安装cmake,请通过sudo apt-get install cmake 命令安装。另外,cmake也有图形化的配置形式,这需要安装cmake-gui (sudo apt-get install cmake-gui)
  使用cmake时需要设置的项与configure差不多:c编译器、c++编译器、设备编译工具链环境和生成的路径。
  指定交叉工具链有多种形式:

  1. 在源码包的CMakeLists.txt中更改配置项
  2. 在执行cmake 命令式行时传入配置项
  3. 新建一个.cmake文件(入toolchain.cmake),在执行cmake时指定此配置文件cmake [path] -DCMAKE_TOOLCHAIN_FILE = ./toolchain.cmake其中path为主CMakeLists的路径。

我采用最简单的编辑CMakeLists这种方法。

配置、构建、编译

  • 设置头文件和库的搜索根路径
    set(CMAKE_FIND_ROOT_PATH "/iMX6_ROOT")
  • 设置生成路径
    set(CMAKE_INSTALL_PERFIX "/home/username/poppler")
  • 设置编辑器
    set(CMAKE_C_COMPILER "arm-poky-linux-gnueabi-gcc")
    set(CMAKE_CXX_COMPILER "arm-poky-linux-gnueabi-g++")
    此外,可以显示指定库文件路径等等选项
    set(CMAKE_LIBRARY_PATH "/iMX6_ROOT/usr/lib")

新建一个目录作为构建目录,我是在源码根目录下新建./build
执行cmake ..

一般地,第一次编译开源软件不会一帆风顺。每个码农的情况都不一样,下面只记录我当时遇到的问题:

  • find_\package找不到freetype的库路径和头文件路径。
    这是因为刚开始没有设置上文提到的查找路径。设置根路径,并且我也设置了库路径和头文件路径
set(CMAKE_FIND_ROOT_PATH xxx)
set(CMAKE_LIBRARY_PATH xxx/lib)
include_directories(xxx/usr/include)
  • 依赖 找不到
    poppler默认依赖的库有些可能目标板环境不存在,只需要更改目标板环境已有的就可以了。
    例如,如果报告libopenjpeg2相关错误则将
set(ENABLE_LIBOPENJPEG "openjpeg2" CACHE STRING "Use libopenjpeg for JPX streams. Possible values: openjpeg2, unmaintained, none. 'unmaintained' gives you the internal unmaintained decoder. Use at your own risk. 'none' compiles no JPX decoder at all. Default: openjpeg2")

中的 openjpeg2 改为 unmaintained 既可。
同样的,如果报告GLIB_MKENUMS相关错误,则将ENABLE_GLIB设置为OFF

option(ENABLE_GLIB "Compile poppler glib wrapper." OFF)

诸如此类的配置,这里给出我的配置部分内容,谨作为参考:

# command line switches
option(ENABLE_XPDF_HEADERS "Install unsupported xpdf headers." OFF)
option(BUILD_GTK_TESTS "Whether compile the GTK+ test programs." OFF)
option(BUILD_QT5_TESTS "Whether compile the Qt5 test programs." OFF)
option(BUILD_CPP_TESTS "Whether compile the CPP test programs." OFF)
option(ENABLE_SPLASH "Build the Splash graphics backend." ON)
option(ENABLE_UTILS "Compile poppler command line utils." OFF)
option(ENABLE_CPP "Compile poppler cpp wrapper." ON)
option(ENABLE_GLIB "Compile poppler glib wrapper." OFF)
option(ENABLE_GOBJECT_INTROSPECTION "Whether to generate GObject introspection." ON)
option(ENABLE_GTK_DOC "Whether to generate glib API documentation." OFF)
option(ENABLE_QT5 "Compile poppler qt5 wrapper." ON)
set(ENABLE_LIBOPENJPEG "unmaintained" CACHE STRING "Use libopenjpeg for JPX streams. Possible values: openjpeg2, unmaintained, none. 'unmaintained' gives you the internal unmaintained decoder. Use at your own risk. 'none' compiles no JPX decoder at all. Default: openjpeg2")
set(ENABLE_CMS "lcms2" CACHE STRING "Use color management system. Possible values: lcms2, none. 'none' disables color management system.")
set(ENABLE_DCTDECODER "libjpeg" CACHE STRING "Use libjpeg for DCT streams. Possible values: libjpeg, unmaintained, none. will use libjpeg if available or fail if not. 'unmaintained' gives you the internal unmaintained decoder. Use at your own risk. 'none' compiles no DCT decoder at all. Default: libjpeg")
option(ENABLE_LIBCURL "Build libcurl based HTTP support." OFF)
option(ENABLE_ZLIB "Build with zlib." OFF)
option(ENABLE_ZLIB_UNCOMPRESS "Use zlib to uncompress flate streams (not totally safe)." OFF)
option(SPLASH_CMYK "Include support for CMYK rasterization." OFF)
option(USE_FIXEDPOINT "Use fixed point arithmetic in the Splash backend" OFF)
option(USE_FLOAT "Use single precision arithmetic in the Splash backend" OFF)
option(BUILD_SHARED_LIBS "Build poppler as a shared library" ON)
  • 配置文件中有一项是指定c++版本set (CMAKE_CXX_STANDARD 11)这一项最好不要改,如果编译后的头文件在使用时报nullptr未定义的错误,则在工程中将nullptr重定义为NULL即可。例如在Qt的.pro中添加DEFINES += nullptr=NULL

基本上,以上配置正确后可以正确编译。poppler的使用在官网有给出example,还是比较简单的。

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值