源码下载地址:https://codeload.github.com/kkzi/qpdf/zip/2681018e300738d6da9a9f89f06c93fc3ef17831
参考:https://blog.51cto.com/u_2194662/5256871
开发环境:QT 5.15.2
1. windows下编译:
编译环境:vs2019+qt5.15.2
vs2019打开工程qpdf.sln
重新生成解决方案后设置test_pdfviewer设为启动项目:
2. Linux (ubuntu x64)
编译环境:gcc_64 qt5.15.2
2.1 修改项目内容:
修改:qpdf/CMakeLists.txt
# add -------------------------------------------------------------------------------
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}") #设置编译C++文件时,使用c++11
message(STATUS "optional:-std=c++11")
endif(CMAKE_COMPILER_IS_GNUCXX)
IF (WIN32)
MESSAGE(STATUS "Now is windows")
add_compile_options(-shared -fPIC)
ELSEIF (APPLE)
MESSAGE(STATUS "Now is Apple systens.")
ELSEIF (UNIX)
MESSAGE(STATUS "Now is UNIX-like OS's. Including aPPLE os x and CygWin")
add_compile_options(-std=c++11 -shared -fPIC) #linux下必须要添加编译选项-fPIC,要不然提示错误
ENDIF ()
#-------------------------------------------------------------------------------------
2.2 ubuntu下载cmake:
Download CMake
# 解压
> tar -zxvf cmake-3.30.2-linux-x86_64.tar.gz
> cd cmake-3.30.2-linux-x86_64
> ./bin/cmake-gui
进入build目录执行make:
执行./test_pdfviewer
3. linux(银河麒麟系统 飞腾cpu aarch64)
编译环境:qt5.15.2
与x64的操作一致,下载对应的cmake版本,若未修改qpdf/CMakeLists.txt
会在最后报错:危险的重寻址:不支持的重定位
多平台编译的例子程序(使用原生平台而不是交叉编译,若使用交叉编译需要修改.pro使其调用对应平台生成的库):
例子下载链接:https://download.csdn.net/download/qq_23903863/89639244
.pro在不同平台使用不同库的配置:
# qpdf path
QPDF_PATH = $${PWD}/qpdf
INCLUDEPATH += $${QPDF_PATH}/include
message($$QMAKESPEC)
win32-msvc
{
LIBS += -L$${QPDF_PATH}/lib/x64
CONFIG(debug, debug | release){
LIBS += -lpdfiumd -lqpdfd
}else{
LIBS += -lpdfium -lqpdf
}
}
unix
{
contains(QT_ARCH, arm64){
message("linux aarch64")
LIBS += -L$${QPDF_PATH}/lib/linux-aarch64
}else{
message("linux x86")
LIBS += -L$${QPDF_PATH}/lib/linux-x64
}
LIBS += -lpdfium -lqpdf
}