我正在尝试在Windows上使用Skia图形库,这需要从源代码构建它。但是,当我运行构建命令时:
ninja -C out/Static
我收到此构建错误:
"C:Program Files (x86)Microsoft Visual Studio2019CommunityVC/Tools/MSVC/14.23.28105/bin/HostX64/x64/cl.exe" /nologo /showIncludes /FC -D_CRT_SECURE_NO_WARNINGS -D_HAS_EXCEPTIONS=0 -DWIN32_LEAN_AND_MEAN -DNOMINMAX -DNDEBUG -DSK_GAMMA_APPLY_TO_A8 -DSKIA_IMPLEMENTATION=1 -DSK_HAS_PNG_LIBRARY "-IC:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/include" "-IC:/Program Files (x86)/Windows Kits/10/Include/10.0.18362.0/shared" "-IC:/Program Files (x86)/Windows Kits/10/Include/10.0.18362.0/ucrt" "-IC:/Program Files (x86)/Windows Kits/10/Include/10.0.18362.0/um" "-IC:/Program Files (x86)/Windows Kits/10/Include/10.0.18362.0/winrt" -I../.. /bigobj /utf-8 /O2 /Zc:inline /GR- /c ../../src/codec/SkPngCodec.cpp /Foobj/src/codec/png.SkPngCodec.obj /Fd"obj/png_c.pdb"
pathtoskiasrccodecSkPngCodec.cpp(25): fatal error C1083: Cannot open include file: 'png.h': No such file or directory
我尝试再次运行它,现在出现不同的错误:
"C:Program Files (x86)Microsoft Visual Studio2019CommunityVC/Tools/MSVC/14.23.28105/bin/HostX64/x64/cl.exe" /nologo /showIncludes /FC -DSK_PDF_USE_SFNTLY -D_CRT_SECURE_NO_WARNINGS -D_HAS_EXCEPTIONS=0 -DWIN32_LEAN_AND_MEAN -DNOMINMAX -DNDEBUG -DSK_GAMMA_APPLY_TO_A8 -DSKIA_IMPLEMENTATION=1 -DSK_SUPPORT_PDF -DSK_HAS_JPEG_LIBRARY -DU_USING_ICU_NAMESPACE=0 "-IC:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/include" "-IC:/Program Files (x86)/Windows Kits/10/Include/10.0.18362.0/shared" "-IC:/Program Files (x86)/Windows Kits/10/Include/10.0.18362.0/ucrt" "-IC:/Program Files (x86)/Windows Kits/10/Include/10.0.18362.0/um" "-IC:/Program Files (x86)/Windows Kits/10/Include/10.0.18362.0/winrt" -I../.. -I../../third_party/externals/sfntly/cpp/src /bigobj /utf-8 /O2 /Zc:inline /GR- /c ../../src/pdf/SkDeflate.cpp /Foobj/src/pdf/pdf.SkDeflate.obj /Fd"obj/pdf_c.pdb"
C:UsersnatanDesktopskiasrcpdfSkDeflate.cpp(16): fatal error C1083: Cannot open include file: 'zlib.h': No such file or directory
如何获取所有这些丢失的文件?
正如 Skia google 组所回答的那样,如果您缺少一些库,则需要通过在生成构建文件时传递skia_use_foo=false
来禁用依赖于缺失库的部分,如下所示:
"bin/gn.exe" gen out/Static --args="is_official_build=true skia_use_libpng=false skia_use_zlib = false skia_use_libjpeg_turbo=false skia_use_harfbuzz=false skia_use_libwebp=false skia_use_expat=false"
然后使用
ninja -C out/Static
如果缺少其他库,请使用查找禁用它们的语法
gn args --list out/Static
(如果您不知道头文件属于哪个库,谷歌搜索也会有所帮助(
几年过去了,也许情况发生了变化,官方文档中有不同的做法.
首先你应该运行python tools/git-sync-deps
下载所有依赖项.
然后,如果你发现在编译过程中仍然找不到头文件,请添加skia_use_system_xxx=false
参数.
这是我在 Windows 上使用的命令:
bin/gn gen out/Static --args='is_official_build=true skia_use_system_libjpeg_turbo=false skia_use_system_zlib=false skia_use_system_harfbuzz=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_expat=false skia_use_system_icu=false'
ninja -C out/Static
这样,您仍然可以编译所有依赖项。唯一的变化是依赖项是从您刚刚下载的位置而不是系统路径获取的。