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 引擎也有了。想干啥干啥去。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM