VS2017 编译pdfium
1、本地创建google目录,进入
2、下载
mkdir google
cd google
gclient config --unmanaged https://pdfium.googlesource.com/pdfium.git
gclient sync
3、修改DEBUG_LEVEL
在DEBUG模式下编译时,会报:
#error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2'
buid/config/BUILD.gn
if (is_win) {
if (!enable_iterator_debugging && !use_custom_libcxx) {
# Iterator debugging is enabled by default by the compiler on debug
# builds, and we have to tell it to turn it off.
#将原来的_HAS_ITERATOR_DEBUGGING=0修改为以下:(确保DEBUG模式时,_ITERATOR_DEBUG_LEVEL为2)
defines += [ "_HAS_ITERATOR_DEBUGGING=1" ]
defines += [ "_ITERATOR_DEBUG_LEVEL=2" ]
}
修改:pdfium/BUILD.gn
config("pdfium_public_config") {
defines = []
if (pdf_enable_v8) {
defines += [ "PDF_ENABLE_V8" ]
if (pdf_enable_xfa) {
defines += [ "PDF_ENABLE_XFA" ]
if (pdf_enable_xfa_bmp) {
defines += [ "PDF_ENABLE_XFA_BMP" ]
}
if (pdf_enable_xfa_gif) {
defines += [ "PDF_ENABLE_XFA_GIF" ]
}
if (pdf_enable_xfa_png) {
defines += [ "PDF_ENABLE_XFA_PNG" ]
}
if (pdf_enable_xfa_tiff) {
defines += [ "PDF_ENABLE_XFA_TIFF" ]
}
if(is_debug){
#增加debug级别
defines += ["_DEBUG"]
defines += ["_HAS_ITERATOR_DEBUGGING=1"]
defines += ["_ITERATOR_DEBUG_LEVEL=2"]
}
}
}
4、生成工程
官方:
#lease refer to Chromium's Visual Studio set up for requirements and instructions on build environment configuration.
#Run set DEPOT_TOOLS_WIN_TOOLCHAIN=0, or set that variable in your global environment.
#Compilation is done through Ninja, not Visual Studio.
use_goma = true # Googlers only. Make sure goma is installed and running first.
is_debug = true # Enable debugging features.
# Set true to enable experimental Skia backend.
pdf_use_skia = false
# Set true to enable experimental Skia backend (paths only).
pdf_use_skia_paths = false
pdf_enable_xfa = true # Set false to remove XFA support (implies JS support).
pdf_enable_v8 = true # Set false to remove Javascript support.
pdf_is_standalone = true # Set for a non-embedded build.
is_component_build = false # Disable component build (Though it should work)
clang_use_chrome_plugins = false # Currently must be false.
For sample applications like pdfium_test to build, one must set pdf_is_standalone = true.
By default, the entire project builds with C++14, because features like V8 support, XFA support, and the Skia backend all have dependencies on libraries that require C++14. If one does not need any of those features, and need to fall back to building in C++11 mode, then set use_cxx11 = true. This fallback is temporary and will go away in the future when PDFium fully transitions to C++14. See this bug for details.
When complete the arguments will be stored in <directory>/args.gn, and GN will automatically use the new arguments to generate build files. Should your files fail to generate, please double-check that you have set use_sysroot as indicated above.
===============
执行:
cd pdfium
set DEPOT_TOOLS_WIN_TOOLCHAIN=0
gn args out/x86
在弹出窗口中,贴:
#Buildargumentsgohere.
#See"gnargs<out_dir>--list"foravailablebuildarguments.
#是否启用goma支持
use_goma=false
#是否编译为Chrome插件
clang_use_chrome_plugins=false
#是否进行编译测试
pdf_is_standalone=true
#是否启用skia支持
pdf_use_skia=false
pdf_use_skia_paths=false
#true编译为debug版本,false编译为release版本
is_debug=true
#true编译为动态库 /MD,/MDd,false编译为静态库 /MT,/MTd
is_component_build=false
#编译为一个独立的静态库(is_component_build必须为false)
#pdf_is_complete_lib为false时,编译为多个静态库,true编译为一个独立的静态库
pdf_is_complete_lib=true
#xfa支持
pdf_enable_xfa=true
#v8支持
pdf_enable_v8=true
#cpu架构;x86、x64可选
target_cpu="x86"
#true将用clang进行编译,false将用VS2017编译
is_clang=false
5、编译pdfium
cd pdfium
ninja -C out/x86 pdfium
编译时间较长,DEBUG结果有900MB以上,RELEASE结果有600M左右