本篇文章主要记录如何从Chromium中提取Base库,方便后续的学习和使用,同时抛砖引玉,希望带给各位一些启发和帮助。
先上提取后的开源代码,可以开箱即用:Github
本次提取基于Tag=77.0.3865.129,也就是77大版本的最后一个子版本,发布时间为2019年10月18日。
文章较长,分上、下两篇,上篇主要讲解如何做,下篇主要讲解问题及解决,大家喜欢可以点点赞。
官方构建文档:77.0.3865.129 + win + build
如果需要其他文档内容,同样修改链接中的对应tag即可,例如线程和任务对应文档修改
原最新代码文档:
https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/threading_and_tasks.md
修改后的对应tag的文档
https://chromium.googlesource.com/chromium/src/+/refs/tags/77.0.3865.129/docs/threading_and_tasks.md
创建一个用于检出代码的目录并切换到该目录。您可以根据需要自定义目录名称和位置,只要完整路径中没有空格即可。
mkdir chromium && cd chromium
运行工具来检出代码及其依赖项。
gclient sync --with_tags --revision 77.0.3865.129
或者从gitee上面拉取源码
git clone --depth 100 -b 103.0.5060.66 https://gitee.com/mirrors/chromium.git src
# 还原git仓库地址
cd src
git remote set-url origin https://chromium.googlesource.com/chromium/src.git
cd ..
--depth 100
意思是拉取深度为100,这将会拉取一些 log,因为编译脚本会基于仓库的 log 反查版本发布时间。
如果这个值太小,可能会查不到,因而报错。所以,建议设为 100 或更大些。
或者,直接去掉这个参数,但这样将拉取全部的 log,特别慢。
-b 103.0.5060.66
指定拉取的 tag 版本。
git fetch https://chromium.googlesource.com/chromium/src.git +refs/tags/77.0.3865.129:b77.0.3865.129 --depth 100
git checkout b77.0.3865.129
注:我没有使用官方的 fetch chromium 指令,是因为这个指令拉取的是主分支最新代码
拉取完代码需要同步第三方依赖
gclient sync
等同于
gclient sync --nohooks
gclient runhooks
注:在 runhooks 阶段,脚本会调用 PowerShell 下载软件包,而 PowserShell 使用的是系统的代理。使用 Charles 代理的话,记得启用 Windows Proxy,仅通过环境变量设置代理是不够的。
执行指令后,要下载几个 G 的依赖包,比较慢,窗口也会输出 Still working on
的提示,防止假死被误关
打开文件:${Chromium_Source}\src\DEPS
找到下面删去devtools-node-module
依赖,这个依赖是Chromium的开发者工具,不关键
'src/third_party/devtools-node-modules':
Var('chromium_git') + '/external/github.com/ChromeDevTools/devtools-node-modules' + '@' + Var('devtools_node_modules_revision')
打开对应的依赖链接发现已经无权限访问(Error NOT_FOUND (googlesource.com)),说明对于老版本的这个依赖已经过期了。
删去后重新运行gclient sync
即可成功生成.gclient_entries
文件
如果有其他不需要的依赖也可以同样操作,加快同步代码的速度
77.0.3865.129
的.gclient_entries
文件内容如下:
entries = {
'src': 'https://chromium.googlesource.com/chromium/src.git',
'src/buildtools/clang_format/script': 'https://chromium.googlesource.com/chromium/llvm-project/cfe/tools/clang-format.git@96636aa0e9f047f17447f2d45a094d0b59ed7917',
'src/buildtools/third_party/libc++/trunk': 'https://chromium.googlesource.com/chromium/llvm-project/libcxx.git@5938e0582bac570a41edb3d6a2217c299adc1bc6',
'src/buildtools/third_party/libc++abi/trunk': 'https://chromium.googlesource.com/chromium/llvm-project/libcxxabi.git@0d529660e32d77d9111912d73f2c74fc5fa2a858',
'src/buildtools/third_party/libunwind/trunk': 'https://chromium.googlesource.com/external/llvm.org/libunwind.git@69d9b84cca8354117b9fe9705a4430d789ee599b',
'src/buildtools/win:gn/gn/windows-amd64': 'https://chrome-infra-packages.appspot.com/gn/gn/windows-amd64@git_revision:152c5144ceed9592c20f0c8fd55769646077569b',
'src/chrome/browser/resources/media_router/extension/src': 'https://chromium.googlesource.com/media_router.git@29324b698ccd8920bc81c71d42dadc6310f0ad0f',
'src/chrome/test/data/perf/canvas_bench': 'https://chromium.googlesource.com/chromium/canvas_bench.git@a7b40ea5ae0239517d78845a5fc9b12976bfc732',
'src/chrome/test/data/perf/frame_rate/content': 'https://chromium.googlesource.com/chromium/frame_rate/content.git@c10272c88463efeef6bb19c9ec07c42bc8fe22b9',
'src/chrome/test/data/xr/webvr_info': 'https://chromium.googlesource.com/external/github.com/toji/webvr.info.git@c58ae99b9ff9e2aa4c524633519570bf33536248',
'src/media/cdm/api': 'https://chromium.googlesource.com/chromium/cdm.git@bc262e26cd2dca812f05bdad3b37398839e63007',
'src/native_client': 'https://chromium.googlesource.com/native_client/src/native_client.git@058a26f57015051953a727add26e7e26348b9558',
'src/net/third_party/quiche/src': 'https://quiche.googlesource.com/quiche.git@753002daef6045500f08066b132da7fd71ab4ca9',
'src/third_party/SPIRV-Tools/src': 'https://chromium.googlesource.com/external/github.com/KhronosGroup/SPIRV-Tools.git@c9190a54da56e425d09e122368b18bcfe00dabf6',
'src/third_party/angle': 'https://chromium.googlesource.com/angle/angle.git@7cf862c9fcd2068a444eef6d4e8a0c1c2170d7f1',
'src/third_party/bison': 'https://chromium.googlesource.com/chromium/deps/bison.git@083c9a45e4affdd5464ee2b224c2df649c6e26c3',
'src/third_party/boringssl/src': 'https://boringssl.googlesource.com/boringssl.git@4dfd5af70191b068aebe567b8e29ce108cee85ce',
'src/third_party/breakpad/breakpad': 'https://chromium.googlesource.com/breakpad/breakpad.git@c46151db0ffd1a8dae914e45f1212ef427f61ed3',
'src/third_party/catapult': 'https://chromium.googlesource.com/catapult.git@c5817614666e57a37bebfb26e1cb85884321533e',
'src/third_party/ced/src': 'https://chromium.googlesource.com/external/github.com/google/compact_enc_det.git@ba412eaaacd3186085babcd901679a48863c7dd5',
'src/third_party/cld_3/src': 'https://chromium.googlesource.com/external/github.com/google/cld_3.git@06f695f1c8ee530104416aab5dcf2d6a1414a56a',
'src/third_party/colorama/src': 'https://chromium.googlesource.com/external/colorama.git@799604a1041e9b3bc5d2789ecbd7e8db2e18e6b8',
'src/third_party/crc32c/src': 'https://chromium.googlesource.com/external/github.com/google/crc32c.git@5998f8451548244de8cde7fab387a550e7c4497d',
'src/third_party/dav1d/libdav1d': 'https://chromium.googlesource.com/external/github.com/videolan/dav1d.git@6ef9a030145eef79fdeab6d4d38e00423ae7a83d',
'src/third_party/dawn': 'https://dawn.googlesource.com/dawn.git@9d2ccaf65c2a370c5f203e119e194a44fa039481',
'src/third_party/depot_tools': 'https://chromium.googlesource.com/chromium/tools/depot_tools.git@3a98df0bdd49d64cb15a5dd0fbc6b43223856e7d',
'src/third_party/dom_distiller_js/dist': 'https://chromium.googlesource.com/chromium/dom-distiller/dist.git@3093c3e238768ab27ff756bd7563ccbb12129d9f',
'src/third_party/emoji-segmenter/src': 'https://chromium.googlesource.com/external/github.com/google/emoji-segmenter.git@9ba6d25d0d9313569665d4a9d2b34f0f39f9a50e',
'src/third_party/ffmpeg': 'https://chromium.googlesource.com/chromium/third_party/ffmpeg.git@e0e3133c40fbca0032a2d9400da736e4b933882f',
'src/third_party/flac': 'https://chromium.googlesource.com/chromium/deps/flac.git@af862024c8c8fa0ae07ced05e89013d881b00596',
'src/third_party/flatbuffers/src': 'https://chromium.googlesource.com/external/github.com/google/flatbuffers.git@9bf9b18f0a705dfd6d50b98056463a55de6a1bf9',
'src/third_party/freetype/src': 'https://chromium.googlesource.com/chromium/src/third_party/freetype2.git@b110acba9e6f7e40314f0da5d249cb3cb3beeab8',
'src/third_party/glfw/src': 'https://chromium.googlesource.com/external/github.com/glfw/glfw.git@2de2589f910b1a85905f425be4d32f33cec092df',
'src/third_party/glslang/src': 'https://chromium.googlesource.com/external/github.com/KhronosGroup/glslang.git@42f813401bdfa640e4b87d8991e63f97fe5d5c43',
'src/third_party/gnu_binutils': 'https://chromium.googlesource.com/native_client/deps/third_party/gnu_binutils.git@f4003433b61b25666565690caf3d7a7a1a4ec436',
'src/third_party/googletest/src': 'https://chromium.googlesource.com/external/github.com/google/googletest.git@b77e5c76252bac322bb82c5b444f050bd0d92451',
'src/third_party/gperf': 'https://chromium.googlesource.com/chromium/deps/gperf.git@d892d79f64f9449770443fb06da49b5a1e5d33c1',
'src/third_party/grpc/src': 'https://chromium.googlesource.com/external/github.com/grpc/grpc.git@74b981a6a3d9ba17f3acae1d72b9109325ef656d',
'src/third_party/harfbuzz-ng/src': 'https://chromium.googlesource.com/external/github.com/harfbuzz/harfbuzz.git@2e7021da7d1726a37822e6a001b9218f82255bc8',
'src/third_party/hunspell_dictionaries': 'https://chromium.googlesource.com/chromium/deps/hunspell_dictionaries.git@3874188bd69fe67a825d07584c74451e45063e95',
'src/third_party/icu': 'https://chromium.googlesource.com/chromium/deps/icu.git@682a230923933a7157a41b88c7804b6b7d2abdfa',
'src/third_party/jsoncpp/source': 'https://chromium.googlesource.com/external/github.com/open-source-parsers/jsoncpp.git@645250b6690785be60ab6780ce4b58698d884d11',
'src/third_party/leveldatabase/src': 'https://chromium.googlesource.com/external/leveldb.git@53e280b56866ac4c90a9f5fcfe02ebdfd4a19832',
'src/third_party/libFuzzer/src': 'https://chromium.googlesource.com/chromium/llvm-project/compiler-rt/lib/fuzzer.git@b9f51dc8c98065df0c8da13c051046f5bab833db',
'src/third_party/libaddressinput/src': 'https://chromium.googlesource.com/external/libaddressinput.git@56c60affb5de83c10ebf5f11d9adcdd70648ab71',
'src/third_party/libaom/source/libaom': 'https://aomedia.googlesource.com/aom.git@625cded0550bb79efd10d98a9809a7ccd72a8f60',
'src/third_party/libjpeg_turbo': 'https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git@14eba7addfdcf0699970fcbac225499858a167f2',
'src/third_party/libphonenumber/dist': 'https://chromium.googlesource.com/external/libphonenumber.git@a4da30df63a097d67e3c429ead6790ad91d36cf4',
'src/third_party/libprotobuf-mutator/src': 'https://chromium.googlesource.com/external/github.com/google/libprotobuf-mutator.git@439e81f8f4847ec6e2bf11b3aa634a5d8485633d',
'src/third_party/libsrtp': 'https://chromium.googlesource.com/chromium/deps/libsrtp.git@650611720ecc23e0e6b32b0e3100f8b4df91696c',
'src/third_party/libvpx/source/libvpx': 'https://chromium.googlesource.com/webm/libvpx.git@18d309c12734d2f06d54ad1716e512153a13ab9d',
'src/third_party/libwebm/source': 'https://chromium.googlesource.com/webm/libwebm.git@51ca718c3adf0ddedacd7df25fe45f67dc5a9ce1',
'src/third_party/libyuv': 'https://chromium.googlesource.com/libyuv/libyuv.git@f9aacffa029ff3a32f0408f78e2588663271f1b1',
'src/third_party/lighttpd': 'https://chromium.googlesource.com/chromium/deps/lighttpd.git@9dfa55d15937a688a92cbf2b7a8621b0927d06eb',
'src/third_party/mingw-w64/mingw/bin': 'https://chromium.googlesource.com/native_client/deps/third_party/mingw-w64/mingw/bin.git@3cc8b140b883a9fe4986d12cfd46c16a093d3527',
'src/third_party/nacl_sdk_binaries': 'https://chromium.googlesource.com/chromium/deps/nacl_sdk_binaries.git@759dfca03bdc774da7ecbf974f6e2b84f43699a5',
'src/third_party/nasm': 'https://chromium.googlesource.com/chromium/deps/nasm.git@f564874f49556d930882645a348fcd6ddc6847b0',
'src/third_party/openh264/src': 'https://chromium.googlesource.com/external/github.com/cisco/openh264@6f26bce0b1c4e8ce0e13332f7c0083788def5fdf',
'src/third_party/openscreen/src': 'https://chromium.googlesource.com/openscreen@d5b3c34bb4b3a1dd65cb13be818596bc81a7855a',
'src/third_party/pdfium': 'https://pdfium.googlesource.com/pdfium.git@7734ba9a7d52f1e4f14fb7a3c84b282684758519',
'src/third_party/pefile': 'https://chromium.googlesource.com/external/pefile.git@72c6ae42396cb913bcab63c15585dc3b5c3f92f1',
'src/third_party/perfetto': 'https://android.googlesource.com/platform/external/perfetto.git@091864c00bffb363a0202fd5b7b1fc30ed04ca17',
'src/third_party/perl': 'https://chromium.googlesource.com/chromium/deps/perl.git@6f3e5028eb65d0b4c5fdd792106ac4c84eee1eb3',
'src/third_party/pywebsocket/src': 'https://chromium.googlesource.com/external/github.com/google/pywebsocket.git@2d7b73c3acbd0f41dcab487ae5c97c6feae06ce2',
'src/third_party/quic_trace/src': 'https://chromium.googlesource.com/external/github.com/google/quic-trace.git@8415c22f0ca2485bd8a16eff64075f4361f3878e',
'src/third_party/re2/src': 'https://chromium.googlesource.com/external/github.com/google/re2.git@9d6788aeb4b2ba27847a7e95a29e7ac08fa58e1b',
'src/third_party/sfntly/src': 'https://chromium.googlesource.com/external/github.com/googlefonts/sfntly.git@48312c98332a4608572459dc71584c2a9dbb1792',
'src/third_party/shaderc/src': 'https://chromium.googlesource.com/external/github.com/google/shaderc.git@8f74bea5b69ab9a2f12f341d9fa542fa69ab83c3',
'src/third_party/skia': 'https://skia.googlesource.com/skia.git@f721da7dc93cbf42084b92f673ce8b6c23452d3f',
'src/third_party/smhasher/src': 'https://chromium.googlesource.com/external/smhasher.git@e87738e57558e0ec472b2fc3a643b838e5b6e88f',
'src/third_party/snappy/src': 'https://chromium.googlesource.com/external/github.com/google/snappy.git@156cd8939c5fba7fa68ae08db843377ecc07b4b5',
'src/third_party/spirv-cross/spirv-cross': 'https://chromium.googlesource.com/external/github.com/KhronosGroup/SPIRV-Cross.git@f07a4e16a60e1d0231dda5d3883550761bd70a47',
'src/third_party/spirv-headers/src': 'https://chromium.googlesource.com/external/github.com/KhronosGroup/SPIRV-Headers.git@123dc278f204f8e833e1a88d31c46d0edf81d4b2',
'src/third_party/swiftshader': 'https://swiftshader.googlesource.com/SwiftShader.git@ec3039253ab805b040ac3a5a42eeec7e84d0377b',
'src/third_party/usrsctp/usrsctplib': 'https://chromium.googlesource.com/external/github.com/sctplab/usrsctp@7a8bc9a90ca96634aa56ee712856d97f27d903f8',
'src/third_party/webdriver/pylib': 'https://chromium.googlesource.com/external/github.com/SeleniumHQ/selenium/py.git@d0045ec570c1a77612db35d1e92f05e1d27b4d53',
'src/third_party/webgl/src': 'https://chromium.googlesource.com/external/khronosgroup/webgl.git@abaae129d9a0c6e1e092067e0b105475df43352e',
'src/third_party/webrtc': 'https://webrtc.googlesource.com/src.git@ad73985e75684cb4ac4dadb9d3d86ad0d66612a0',
'src/third_party/yasm/source/patched-yasm': 'https://chromium.googlesource.com/chromium/deps/yasm/patched-yasm.git@720b70524a4424b15fc57e82263568c8ba0496ad',
'src/tools/luci-go:infra/tools/luci/isolate/${platform}': 'https://chrome-infra-packages.appspot.com/infra/tools/luci/isolate/${platform}@git_revision:7d11fd9e66407c49cb6c8546a2ae45ea993a240c',
'src/tools/luci-go:infra/tools/luci/isolated/${platform}': 'https://chrome-infra-packages.appspot.com/infra/tools/luci/isolated/${platform}@git_revision:7d11fd9e66407c49cb6c8546a2ae45ea993a240c',
'src/tools/luci-go:infra/tools/luci/swarming/${platform}': 'https://chrome-infra-packages.appspot.com/infra/tools/luci/swarming/${platform}@git_revision:7d11fd9e66407c49cb6c8546a2ae45ea993a240c',
'src/tools/page_cycler/acid3': 'https://chromium.googlesource.com/chromium/deps/acid3.git@6be0a66a1ebd7ebc5abc1b2f405a945f6d871521',
'src/tools/skia_goldctl:skia/tools/goldctl/${platform}': 'https://chrome-infra-packages.appspot.com/skia/tools/goldctl/${platform}@git_revision:343c20ec0539c9d390d11dc566eab245561234f9',
'src/tools/swarming_client': 'https://chromium.googlesource.com/infra/luci/client-py.git@96f125709acfd0b48fc1e5dae7d6ea42291726ac',
'src/v8': 'https://chromium.googlesource.com/v8/v8.git@02a3469f07e23c4ebb473818dcb9d29949f966f6',
'src/third_party/angle/third_party/deqp/src': 'https://chromium.googlesource.com/external/deqp@d3eef28e67ce6795ba3a2124aaa977819729d45f',
'src/third_party/angle/third_party/glmark2/src': 'https://chromium.googlesource.com/external/github.com/glmark2/glmark2@c4b3ff5a481348e8bdc2b71ee275864db91e40b1',
'src/third_party/angle/third_party/rapidjson/src': 'https://chromium.googlesource.com/external/github.com/Tencent/rapidjson@7484e06c589873e1ed80382d262087e4fa80fb63',
'src/third_party/angle/third_party/vulkan-headers/src': 'https://chromium.googlesource.com/external/github.com/KhronosGroup/Vulkan-Headers@982f0f84dccf6f281b48318c77261a9028000126',
'src/third_party/angle/third_party/vulkan-loader/src': 'https://chromium.googlesource.com/external/github.com/KhronosGroup/Vulkan-Loader@2f0abfcf9eb04018e6e92125a70bc28665aa17fe',
'src/third_party/angle/third_party/vulkan-tools/src': 'https://chromium.googlesource.com/external/github.com/KhronosGroup/Vulkan-Tools@f392e71b994036c92b896c2a62cc63d042b7f9b1',
'src/third_party/angle/third_party/vulkan-validation-layers/src': 'https://chromium.googlesource.com/external/github.com/KhronosGroup/Vulkan-ValidationLayers@ff80a937c8a505abbdddb95d8ffaa446820c8391',
'src/third_party/openscreen/src/third_party/tinycbor/src': 'https://chromium.googlesource.com/external/github.com/intel/tinycbor.git@bfc40dcf909f1998d7760c2bc0e1409979d3c8cb',
}
错误信息:D:\Code\chromium_msvc\src\build\vs_toolchain.py
raise Exception('Visual Studio Version %s (from GYP_MSVS_VERSION)'
' not found.' % version_as_year)
提示Visual Studio未找到对应版本
# VS versions are listed in descending order of priority (highest first).
MSVS_VERSIONS = collections.OrderedDict([
('2017', '15.0'),
('2019', '16.0')
])
目前根据官网文档,仅支持vs2017和vs2019【Visual Studio 2017 (>=15.7.2) or 2019 (>=16.0.0)】
windows SDK需要版本高于【10.0.18362 】
安装好Vs2019后设置系统环境变量
安装时组件勾选:
1、clang相关
2、ATL和MFC相关支持
3、windows SDK,版本高于10.0.18362即可
对比正确的Chromium源码和目标源码,在src\build\util目录下的确缺少了对应的LASTCHANGE.committime和LASTCHANGE两个文件
解决:重新运行gclient sync可以重新恢复这两个文件,并且下载缺失的组件。
此问题会出现在未安装vs2019即运行了gclient sync,然后再安装了vs2019,运行gn gen会出现
拷贝正常源码的third_party文件夹中的ninja到此源码对应目录中:ninja
配置清单:gn args out\Default --list > args.txt
生成vs解决方案命令行如下:
gn gen --ide=vs2019 --ninja-executable=D:\Code\chromium_msvc\src\third_party\ninja\ninja.exe --filters=//base out/Default
生成的解决方案中的base库有project文件,参考这个project我们构建属于自己独立的项目文件,可以新建项目Base,然后单独进行配置编译。
项目配置是重中之重,项目不配置好是无法编译通过。
具体文件可以参考:proj
可能根据每个人软件安装和系统环境不同略有不同,仅供参考
D:\Code\CoreP\src\Chromium
D:\Code\chromium_base\src // 主要引入第三方库和build文件夹
D:\Code\chromium_base\src\out\Default\gen // 主要引入一些模块的build_config文件夹,例如D:\Code\chromium\src\out\Default\gen\base\message_loop\message_pump_buildflags.h
D:\Code\chromium_base\src\third_party\boringssl\src\include // 第三方库头文件,如果是作为dll的话需要解决第三方库的依赖问题
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<UseStructuredOutput>false</UseStructuredOutput>
<LibraryPath>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\lib\x86;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\atlmfc\lib\x86;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\VS\lib\x86;C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\ucrt\x86;C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\um\x86;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x86</LibraryPath>
<ExternalIncludePath>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\atlmfc\include;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\VS\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared;C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\winrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\cppwinrt;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\Include\um</ExternalIncludePath>
<IncludePath>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\atlmfc\include;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\VS\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared;C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\winrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\cppwinrt;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\Include\um</IncludePath>
<ReferencePath>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\atlmfc\lib\x86;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\lib\x86;$(ReferencePath)</ReferencePath>
<OutDir>$(SolutionDir)..\Bin\BinDebug\</OutDir>
<IntDir>$(SolutionDir)\obj\BinDebug\$(ProjectName)\$(Configuration)\</IntDir>
</PropertyGroup>
说明:如果安装了vs2022以及最新的windows SDK以及运行时库,可能会去找10.0.22621.0
-C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
以及14.38.33130
-D:\Software\Microsoft Visual Studio\2022\Professional\VC\Redist\MSVC\14.38.33130
导致编译失败,可以手动指定依赖VC的目录,注意勾选下面继承
先上图,再详细说明
注意事项:(配置选项均严格参考生成的解决方案中base.proj里面的配置)
D:\Code\chromium_base\src\out\Default\obj\base\base.vcxproj
SDK = 10.0.18362.0
平台工具集 = v142 (visual studio 2019)
c++语言标准 = C++ 17
禁用内联函数扩展(/Ob0)
USE_AURA=1;NO_TCMALLOC;FULL_SAFE_BROWSING;SAFE_BROWSING_CSD;SAFE_BROWSING_DB_LOCAL;CHROMIUM_BUILD;_HAS_EXCEPTIONS=0;__STD_C;_CRT_RAND_S;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_DEPRECATE;_ATL_NO_OPENGL;_USING_V110_SDK71_;_WINDOWS;CERT_CHAIN_PARA_HAS_EXTRA_FIELDS;PSAPI_VERSION=2;WIN32;_SECURE_ATL;WINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP;WIN32_LEAN_AND_MEAN;NOMINMAX;_UNICODE;UNICODE;NTDDI_VERSION=NTDDI_WIN10_RS2;_WIN32_WINNT=0x0A00;WINVER=0x0A00;_DEBUG;DYNAMIC_ANNOTATIONS_ENABLED=1;_HAS_ITERATOR_DEBUGGING=0;BASE_IMPLEMENTATION;BORINGSSL_SHARED_LIBRARY;COMPONENT_BUILD;%(PreprocessorDefinitions)
以下是对一些常见预定义宏和编译选项的简要说明:
启用函数级链接:是(/Gy)
符合模式:否(/permissive)
启用运行时类型信息:否(/GR)
禁用特定警告:
4117;4091;4127;4251;4275;4312;4324;4351;4355;4503;4589;4611;4100;4121;4244;4505;4510;4512;4610;4838;4995;4996;4456;4457;4458;4459;4200;4201;4204;4221;4245;4267;4305;4389;4702;4701;4703;4661;4706;4715;4267;4702;4577;
问题集锦见文章下篇
Dbghelp.lib
version.lib
Ws2_32.lib
Winmm.lib
Userenv.lib
modp_b64.lib
wbemuuid.lib
Powrprof.lib
Propsys.lib
shlwapi.lib
Setupapi.lib
pe_image.lib
boringssl.lib
dynamic_annotations.lib
忽略:LIBCMTD.lib
USE_AURA=1
NO_TCMALLOC
FULL_SAFE_BROWSING
SAFE_BROWSING_CSD
SAFE_BROWSING_DB_LOCAL
CHROMIUM_BUILD
_HAS_EXCEPTIONS=0
__STD_C
_CRT_RAND_S
_CRT_SECURE_NO_DEPRECATE
_SCL_SECURE_NO_DEPRECATE
_ATL_NO_OPENGL
_USING_V110_SDK71_
_WINDOWS
CERT_CHAIN_PARA_HAS_EXTRA_FIELDS
PSAPI_VERSION=2
WIN32
_SECURE_ATL
WINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP
WIN32_LEAN_AND_MEAN
NOMINMAX
_UNICODE
UNICODE
NTDDI_VERSION=NTDDI_WIN10_RS2
_WIN32_WINNT=0x0A00
WINVER=0x0A00
_DEBUG
DYNAMIC_ANNOTATIONS_ENABLED=1
_HAS_ITERATOR_DEBUGGING=0
BASE_IMPLEMENTATION
BORINGSSL_SHARED_LIBRARY
COMPONENT_BUILD
BORINGSSL_IMPLEMENTATION
D:\Code\CoreP\src\Chromium;D:\Code\CoreP\src;D:\Code\chromium_base\src;D:\Code\chromium_base\src\out\Default\gen;$(SolutionDir)..\src\third_party\boringssl\src\include;
使用时效果图如下,具体源码学习可以参考Chromium学习
正常引入base库的头文件,会额外引入前面环节生成的额外产物,例如
D:\Code\chromium_base\src\build
目录下的build_config.h
和buildflag.h
D:\Code\chromium_base\src\out\Default\gen
目录下的base文件夹中所有文件
这些文件都是自定义编译选项宏定义,后续可以合并迁移至单独头文件进行控制即可
环境VS2022 17.8.3 + WindowSDK[10.0.22621.0]
Microsoft Visual Studio Professional 2022
版本 17.8.3
VisualStudio.17.Release/17.8.3+34330.188
Microsoft .NET Framework
版本 4.8.09032
已安装的版本: Professional
Visual C++ 2022 00483-10900-95169-AA160
Microsoft Visual C++ 2022
ASP.NET and Web Tools 17.8.358.6298
ASP.NET and Web Tools
Azure 应用服务工具 3.0.0 版 17.8.358.6298
Azure 应用服务工具 3.0.0 版
C# 工具 4.8.0-7.23572.1+7b75981cf3bd520b86ec4ed00ec156c8bc48e4eb
IDE 中使用的 C# 组件。可能使用其他版本的编译器,具体取决于你的项目类型和设置。
Cookiecutter 17.0.23262.1
提供以 cookiecutter 格式查找、实例化和自定义模板的工具。
File Icons 2.7
Adds icons for files that are not recognized by Solution Explorer
Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
Node.js 工具 1.5.50908.1 Commit Hash:c294679b821c4b8f7f9c6db3827b7655db80fc28
Visual Studio 中新增了对开发和调试 Node.js 应用的支持
NuGet 包管理器 6.8.0
Visual Studio 中的 NuGet 包管理器。有关 NuGet 的详细信息,请访问 https://docs.nuget.org/
Python - 分析支持 17.0.23262.1
对 Python 项目的分析支持。
Qt Visual Studio Tools 3.0.2
The Qt VS Tools for Visual Studio 2022 allow developers to use the standard development environment without having to worry about any Qt-related build steps or tools.
TypeScript Tools 17.0.20920.2001
TypeScript Tools for Microsoft Visual Studio
Visual Assist 10.9.2508.0
For more information about Visual Assist, see the Whole Tomato Software website at http://www.WholeTomato.com. Copyright (c)1997-2023 Whole Tomato Software, LLC
Visual Basic 工具 4.8.0-7.23572.1+7b75981cf3bd520b86ec4ed00ec156c8bc48e4eb
IDE 中使用的 Visual Basic 组件。可能使用其他版本的编译器,具体取决于你的项目类型和设置。
Visual F# Tools 17.8.0-beta.23475.2+10f956e631a1efc0f7f5e49c626c494cd32b1f50
Microsoft Visual F# Tools
Visual Studio IntelliCode 2.2
Visual Studio 的 AI 协助开发。
带 Pylance 的 Python 17.0.23262.1
为 Python 开发人员提供 IntelliSense、项目、模板、调试、交互窗口和其他支持。
适用于 Google Test 的测试适配器 1.0
启用带有针对 Google Test 编写的单元测试的 Visual Studio 测试工具。扩展安装目录中提供了使用条款和第三方通知。
用于 Boost.Test 的测试适配器 1.0
通过针对 Boost.Test 编写的单元测试启用 Visual Studio 测试工具。扩展安装目录中提供用户条款和第三方通知。
调整Windows SDK版本【均才用v143(visual studio 2022)】
boringssl[lib] 10.0.18362.0 -> 10.0.22621.0[最新] pass
dynamic_annotations[lib] 10.0.18362.0 -> 10.0.22621.0[最新] pass
modp_b64[lib] 10.0.18362.0 -> 10.0.22621.0[最新] pass
pe_image[lib] 10.0.18362.0 -> 10.0.22621.0[最新] pass
base[dll] 10.0.18362.0 -> 10.0.22621.0[最新] pass
修改VC++的包含路径
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<UseStructuredOutput>false</UseStructuredOutput>
<LibraryPath>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\lib\x86;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\atlmfc\lib\x86;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\VS\lib\x86;C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\ucrt\x86;C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\um\x86;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x86</LibraryPath>
<ExternalIncludePath>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\atlmfc\include;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\VS\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared;C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\winrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\cppwinrt;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\Include\um</ExternalIncludePath>
<IncludePath>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\atlmfc\include;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\VS\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared;C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\winrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\cppwinrt;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\Include\um</IncludePath>
<ReferencePath>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\atlmfc\lib\x86;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\lib\x86;$(ReferencePath)</ReferencePath>
<LibraryPath>
改为如下,使用系统默认
</LibraryPath>
<ExternalIncludePath>$(ExternalIncludePath)</ExternalIncludePath>
<IncludePath>$(IncludePath)</IncludePath>
<ReferencePath>$(ReferencePath)</ReferencePath>
<OutDir>$(SolutionDir)..\Bin\BinDebug\</OutDir>
<IntDir>$(SolutionDir)\obj\BinDebug\$(ProjectName)\$(Configuration)\</IntDir>
</PropertyGroup>
找到问题文件:D:\Code\CorP_Base\src\Chromium\Base\trace_event\trace_event_memory_overhead.h
新增#include<string>
即可
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22621.0\um\x86\DbgHelp.Lib
项目属性 - VC++目录 - 库目录缺失导致,新增
$(VC_LibraryPath_x86)
$(WindowsSDK_LibraryPath_x86)
读到这里,给大家点个赞,基本上提取一个开源库的功能模块都是大致的流程,最终成果在这里,感兴趣的看官可以自行下载进行学习哈,码字不易求个赞,谢谢。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。