使用curl测试是否通
curl.exe http://www.google.com
1、vs下载遗漏组件
the “MFC/ATL support” sub-components. This can be done from the command line by passing these arguments to the Visual Studio installer (see below for ARM64 instructions)
2、安装SDK Debugging Tools工具
同时添加构建工具系统环境路径,构建需要gn 和 ninja
gn.exe
ninja.exe
系统环境变量添加两个exe对应本地目录:D:\Work\code\pdf
windows环境配置
pdfium源码编译依赖较多,环境配置比较复杂,结合pdfium官网
官网 https://pdfium.googlesource.com/pdfium/(Google pdfium官网,需要VPN才能访问)
配置代理
配置代理可以参考w3上链接配置,配置代理过程比较复杂。配置有问题,拉取depot_tools工具和源码时会出现超时错误
set HTTP_PROXY=http://127.0.0.1:3128
set HTTPS_PROXY=http://127.0.0.1:3128
git config --global http.proxy http://127.0.0.1:3128
git config --global https.proxy http://127.0.0.1:3128
取消代理
!!!配置代理会影响其他代码拉取过程,取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy
visual studio 2017或visual studio 2022
VS还需下载组件
o 安装Desktop development with C++
o 安装MFC/ATL support
系统环境变量添加 vs2017_install=xxx\Microsoft Visual Studio\2017\Professional
windows kits 10
下载地址 https://developer.microsoft.com/en-us/windows/downloads/windows-sdk/
系统环境变量添加 WINDOWSSDKDIR= xxx\Windows Kits\10
depot_tools
depot_tools工具目录中包含了构建编译pdfium的工具gn,ninjia,depot_tools可以通过pdfium官网git命令获取或者取用别人pull下来的
提供pdfium源码构建编译工具
Path中添加系统环境变量 xxx\depot_tools
连接上VPN,就可以直接拉取代码了,不需要其他proxy的配置
gclient config --unmanaged https://pdfium.googlesource.com/pdfium.git
gclient sync
用git bash here,最后报错了
按照显示目录,一个个目录拉取corpus icu skia
解决方法:
error: RPC failed; curl 92 HTTP/2 stream 1 was not closed cleanly before end of the underlying stream
[0:15:53] error: RPC failed; curl 56 OpenSSL SSL_read: Connection was reset, errno 10054
[0:15:53] error: 15312 bytes of body are still expected
都是同一类问题,通过配置如下命令解决
git config --global http.version HTTP/1.1
git config --global http.postBuffer 157286400
用cmd
拉取代码需要配置代理(已有代码没必须)
windows编译
编译代码之前需要设置
set DEPOT_TOOLS_WIN_TOOLCHAIN=0
不设置,代码同步完成后,会提示 “No downloadable toolchain. In order to use your locally installed version of Visual Studio to build Chrome pelease set DEPOT_TOOLS_WIN_TOOLCHAIN=0”
set WINDOWSSDKDIR=D:\Windows Kits\10 # 必须设置win10 sdk(需要配置,如果没有window kits,到指定网站下载)
set vs2017_install=D:\Tool\Microsoft Visual Studio\2017\Professional
#必须配置,不设置会报错ERROR at //build/config/win/visual_studio_version.gni:27:7: Script returned non-zero exit code.
说明:将以上三条set命名添加到系统变量中,每次下载代码就不需要执行上面三条命令了
DEPOT_TOOLS_WIN_TOOLCHAIN 0
WINDOWSSDKDIR D:\Windows Kits\10
vs2017_install D:\Tool\Microsoft Visual Studio\2017\Professional
或者
vs2022_install D:\Tool\Microsoft Visual Studio\2022\Professional
取决于本地vs版本,添加对应版本路径
android代码拉取
Android编译过程
配置git代理:
git config --global http.proxy http://xx:[email protected]:8080
git config --global https.proxy http://xx:[email protected]:8080
环境变量配置代理:
export http_proxy=http://xx:[email protected]:8080
export https_proxy=http://xx:[email protected]:8080
安装depot_tools
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
depot_tools环境变量设置:
export PATH=“$PATH:/data/shanhaiyang/pdfium/depot_tools”
同步代码
gclient config --unmanaged https://pdfium.googlesource.com/pdfium.git
#此步骤必须,否则拉取代码三方库中没有android_ndk catapult等目录
echo “target_os = [‘android’]” >> .gclient
gclient sync
!!!重要:拉取代码过程较久,大概需要40min-50min,拉取完代码先确认下三方库 third_party 中目录是否完整,android_ndk catapult等(每一步流程都很重要啊!!!)
android编译
修改脚本pdfium/BUILD.gn
修改点1:
if (pdf_use_skia_paths) {
defines += [ “SKIA_SUPPORT_PATHS” ]
}后增加-g选项
cflags += [“-g”]
修改点2:
config(“pdfium_common_config”) {
cflags = [ “-fvisibility=default” ] # add
ldflags = []
include_dirs = [ “.” ]
defines = [
“PNG_PREFIX”,
“PNG_USE_READ_MACROS”,
“FPDFSDK_EXPORTS”, # add (前面只能是4个空格,否则不能识别)
]
修改点3:
group(“pdfium_public_headers”) {
public_deps = [ “:pdfium_public_headers_impl” ]
public_configs = [
“:pdfium_public_config”,
“:pdfium_implementation_config”,
]
}后增加
shared_library(“pdfsdk”) {
deps = [“:pdfium”] # 不能注释
if (target_os == “android”) {
configs -= [ “//build/config/android:hide_all_but_jni_onload” ]
}
}
修改点4:pdfium/build_overrides/build.gni
注释代码
#if (current_cpu == “arm”) {
#arm_use_neon = true
#}
设置编译参数
v8编译参数
target_os=“android”
target_cpu=“arm64”
pdf_bundle_freetype=true
pdf_is_standalone=false
is_component_build=false
pdf_enable_xfa=false
pdf_enable_v8=false
is_debug=false
is_official_build=true
V7编译参数
target_os=“android”
target_cpu=“arm”
arm_version=7
pdf_bundle_freetype=true
pdf_is_standalone=false
is_component_build=false
pdf_enable_xfa=false
pdf_enable_v8=false
is_debug=false
is_official_build=true
需要将usr.lib拷贝到对应目录
编译
注:详细编译过程:http://i.lckiss.com/?p=5897
4、生成编译目录
生成编译目录,生成路径D:\Work\code\pdf\pdf\pdf_gn\pdfium\out\Build
gn gen out/win64
gn gen out/win32
gn gen out/win321
5、设置编译参数
设置编译参数脚本(自动打开args.gn脚本)
各参数含义:https://ty969975553.github.io/2021/03/23/pdfium%E7%BC%96%E8%AF%91%E7%AC%94%E8%AE%B0/
三方库默认编译参数:pdfium.gni
gn args out/win64
gn args out/win32
gn args out/win321
args.gn导入编译参数
#是否启用 goma 支持
use_goma = false
#是否编译为 Chrome 插件
clang_use_chrome_plugins = false
#是否进行编译测试
pdf_is_standalone = false
#是否启用 skia 支持
pdf_use_skia = false
#true 编译为 debug 版本,false 编译为 release 版本
is_debug = false
#true 编译为动态库,false 编译为静态库
is_component_build = false
#编译为一个独立的静态库(is_component_build 必须为 false)
#pdf_is_complete_lib 为 false 时, 编译为多个静态库,true 编译为一个独立的静态库
pdf_is_complete_lib = true
#xfa 支持
pdf_enable_xfa = false
#v8 支持;启用 v8 后,编译时间会增加
pdf_enable_v8 = false
#cpu 架构;x86、x64 可选
target_cpu = “x64” # 或32位
target_cpu = “x86”
#true 将用 clang 进行编译,false 将用 VS2017 编译
#true,设置成false会报错
is_clang = true
说明:
1、is_clang = true,必须设置成true,否则编译无法通过(也可以不设置)
2、这些编译参数设置后无法编译通过
use_custom_libcxx_for_host=false
use_custom_libcxx=false
libcxx_abi_unstable=false
3、禁用v8可以提高编译性能,使用clang可以提高编译和程序运行性能,如果VS编译不通过,就尝试使用clang试试。
!!!重点修改:
D:\Work\code\pdf\pdf\pdf_gn\pdfium\out\x64(x86)\obj
修改 pdfium.ninja 文件, 追加部分内容(pdfium.ninja中的内容保留)
复制D:\Work\code\pdf\pdf\libcxx\Untitle.txt 目录下内容,拷贝如下类容
obj/buildtools/third_party/libc++/libc++/algorithm.obj obj/buildtools/third_party/libc++/libc++/any.obj obj/buildtools/third_party/libc++/libc++/atomic.obj obj/buildtools/third_party/libc++/libc++/barrier.obj obj/buildtools/third_party/libc++/libc++/bind.obj obj/buildtools/third_party/libc++/libc++/charconv.obj obj/buildtools/third_party/libc++/libc++/chrono.obj obj/buildtools/third_party/libc++/libc++/condition_variable.obj obj/buildtools/third_party/libc++/libc++/condition_variable_destructor.obj obj/buildtools/third_party/libc++/libc++/debug.obj obj/buildtools/third_party/libc++/libc++/exception.obj obj/buildtools/third_party/libc++/libc++/functional.obj obj/buildtools/third_party/libc++/libc++/future.obj obj/buildtools/third_party/libc++/libc++/hash.obj obj/buildtools/third_party/libc++/libc++/ios.instantiations.obj obj/buildtools/third_party/libc++/libc++/ios.obj obj/buildtools/third_party/libc++/libc++/iostream.obj obj/buildtools/third_party/libc++/libc++/locale.obj obj/buildtools/third_party/libc++/libc++/locale_win32.obj obj/buildtools/third_party/libc++/libc++/memory.obj obj/buildtools/third_party/libc++/libc++/mutex.obj obj/buildtools/third_party/libc++/libc++/mutex_destructor.obj obj/buildtools/third_party/libc++/libc++/new.obj obj/buildtools/third_party/libc++/libc++/optional.obj obj/buildtools/third_party/libc++/libc++/random.obj obj/buildtools/third_party/libc++/libc++/random_shuffle.obj obj/buildtools/third_party/libc++/libc++/regex.obj obj/buildtools/third_party/libc++/libc++/shared_mutex.obj obj/buildtools/third_party/libc++/libc++/stdexcept.obj obj/buildtools/third_party/libc++/libc++/string.obj obj/buildtools/third_party/libc++/libc++/strstream.obj obj/buildtools/third_party/libc++/libc++/support.obj obj/buildtools/third_party/libc++/libc++/system_error.obj obj/buildtools/third_party/libc++/libc++/thread.obj obj/buildtools/third_party/libc++/libc++/thread_win32.obj obj/buildtools/third_party/libc++/libc++/typeinfo.obj obj/buildtools/third_party/libc++/libc++/utility.obj obj/buildtools/third_party/libc++/libc++/valarray.obj obj/buildtools/third_party/libc++/libc++/variant.obj obj/buildtools/third_party/libc++/libc++/vector.obj
obj/buildtools/third_party/libc++/libc++/d2fixed.obj obj/buildtools/third_party/libc++/libc++/d2s.obj
obj/buildtools/third_party/libc++/libc++/f2s.obj
直接拷贝到 alink 之后,
!!!备份代码win64,直接编译,可以不需要增加.obj操作
D:\Work\code\pdf\pdf\pdf_gn\pdf_back\google\pdfium
5、编译
lib生成目录:D:\Work\code\pdf\pdf\pdf_gn\pdfium\out\Default\obj
源码目录执行
ninja -C out/win64 pdfium -j16
ninja -C out/win32 pdfium -j16
清除文件目录
ninja -C out/win64 pdfium -t clean