win10编译pdfium

在win10+vs2019下编译pdfium动态库。

准备工作

需要预先安装的有:

  • vs2019(最低是2017)
  • python
  • depot_tools
  • ninja
  • vpn(ss)

ss开启本地代理端口1081,ss的1081端口,全局模式,将所有流量都代理出去。

环境设置

 

cmd以管理员方式打开

 

--设置全局环境变量代理
set HTTP_PROXY=127.0.0.1:1081
set HTTPS_PROXY=127.0.0.1:1081

set DEPOT_TOOLS_WIN_TOOLCHAIN=0 
set GYP_MSVS_VERSION=2017

 

1、下载 depot_tools 源码; 
              https://chromium.googlesource.com/chromium/tools/depot_tools.git
              下载完成后,将下载的 depot_tools 源码目录添加系统搜索路径之中;

2、下载 PDFium 源码;
              gclient config --unmanaged https://pdfium.googlesource.com/pdfium.git
              gclient sync
              确保下载完整。看看 pdfium\third_party\llvm-build\Release+Asserts\bin 目录下面是否有 clang-cl.exe 如果有,
              代表下载完整,否则用 gclient sync 再次更新下载。

 

mkdir repo 
cd repo
gclient config --unmanaged https://pdfium.googlesource.com/pdfium.git
gclient sync
cd pdfium

 


在下载的过程中,可能会遇到几个错误,例如下载clang-format始终下载不了,这个可以忽略,修改repo/pdfium/DEPS文件, 将关于clang_format_win的hook段删除掉。 然后再次执行gclient sync重试。在需要安装的路径下,执行以下命令:

  1 
2
3
4
5
6
7
8
9
10
11
12
  { 
# Pull clang-format binaries using checked-in hashes.
'name' : 'clang_format_win' ,
'pattern' : '.' ,
'action' : [ 'download_from_google_storage' ,
'--no_resume' ,
'--platform=win32' ,
'--no_auth' ,
'--bucket' , 'chromium-clang-format' ,
'-s' , 'pdfium/buildtools/win/clang-format.exe.sha1' ,
],
},

编译

 

 

repo/pdfium中,执行以下命令

  1 
  gn args out/Release 

将会在repo/pdfium目录下产生一个out/Release子目录,后续编译的文件都在这里。

然后会弹出一个文本编辑器,要求输入编译选项,这里贴我的配置:

  1 
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  # Build arguments go here. 
# See "gn args <out_dir> --list" for available build arguments.
use_goma = false # Googlers only. Make sure goma is installed and running first.
is_debug = false # 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 = false # Set false to remove XFA support (implies JS support).
pdf_enable_v8 = false # Set false to remove Javascript support.
pdf_is_standalone = true # Set for a non-embedded build.
is_component_build = false # Disable component build (must be false)

clang_use_chrome_plugins = false # Currently must be false.

成功之后,执行:

  1 
  ninja -C out/Release pdfium 

最后发现什么都没得到。 google一下,才知道pdfium不会生成动态库。 所以寻找了很久的解决方案,最后在repo/pdfium/BUILD.gn文件中,修改如下:

  • 修改pdfium_common_config ,添加define为: FPDFSDK_EXPORTS
  • jumbo_static_library修改为shared_library

然后重新执行ninja -C out/Release pdfium , 最终得到了pdfium.dll文件。

如果需要构建32位的动态库,需要修改repo/pdfium/out/Release/args.gn ,添加一行

  1 
  target_cpu= "x86" 

 

 

vs构建

也可以使用vs来构建项目。 repo/pdfium中执行

  1 
  gn gen --ide=vs out/Dev 

然后会生成一个all.sln的解决方案。 vs打开,执行构建,漫长等待之后,也会出现pdfium.dll。

二、编译:
         进入 PDFium 源码目录,
                1、在命令行上输入:gn args zout/VSX86,此时会弹出编译选项文本,要你输入。不输入也可以
                      (默认生成 x64、动态库版本。编译选项见下面三)。此时会生成 zout/VSX86 目录和一堆文件。
                     如果希望用 VS 的 IDE 来编译,可用:gn args --ide=vs zout/VSX86,来代替:gn args zout/VSX86,
      这样会生成 zout/VSX86/all.sln 工程文件。用 VS 打开编译就可以了。
                2、再次在命令行上输入:ninja -C zout/VSX86 pdfium,进行编译。
                      编译过程会根据编译选项不同,花费的时间不同。测试发现 Clang-cl 比 VS2017 明显编译要快。

  三、编译选项:        

  1.  
    # 是否启用 goma 支持
  2.  
    use_goma = false
  3.  
     
  4.  
    # 是否编译为 Chrome 插件
  5.  
    clang_use_chrome_plugins = false
  6.  
     
  7.  
    # 是否进行编译测试
  8.  
    pdf_is_standalone = true
  9.  
     
  10.  
    # 是否启用 skia 支持
  11.  
    pdf_use_skia = false
  12.  
    pdf_use_skia_paths = false
  13.  
     
  14.  
    # true 编译为 debug 版本,false 编译为 release 版本
  15.  
    is_debug = false
  16.  
     
  17.  
    # true 编译为动态库,false 编译为静态库
  18.  
    is_component_build = false
  19.  
     
  20.  
    # 编译为一个独立的静态库(is_component_build 必须为 false)
  21.  
    # pdf_is_complete_lib 为 false 时, 编译为多个静态库,true 编译为一个独立的静态库
  22.  
    pdf_is_complete_lib = false
  23.  
     
  24.  
    # xfa 支持
  25.  
    pdf_enable_xfa = false
  26.  
     
  27.  
    # v8 支持;启用 v8 后,编译时间会增加
  28.  
    pdf_enable_v8 = true
  29.  
     
  30.  
    # cpu 架构;x86、x64 可选
  31.  
    target_cpu = "x86"
  32.  
     
  33.  
    # true 将用 clang 进行编译,false 将用 VS2017 编译
  34.  
    is_clang = false
  35.  
     

 如果启用了 V8 编译,那么 V8 引擎也有了。想干啥干啥去。

posted @ 2020-08-02 23:29  特洛伊-Micro  阅读(4197)  评论(1编辑  收藏  举报