鉴于WebRTC更新速度较快且在编译过程中遇到了一些问题,故将此次编译过程在网上相关教程的基础之上进行了以下记录。
WebRTC版本:
打开VS Installer,点击修改,勾选如下选项进行下载:
cd depot_tools
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
depot_tools和webrtc的拉取默认使用者会科学工具)
在创建好相关目录之后,进行如下操作:
cd webrtc
gclient config --name src https://chromium.googlesource.com/external/webrtc.git
fetch --nohooks webrtc
gclient sync
拉取和同步所需的时间较长。
set GYP_MSVS_VERSION=2019
set GYP_MSVS_OVERRIDE_PATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional
set GYP_GENERATORS=msvs-ninja,ninja
set DEPOT_TOOLS_WIN_TOOLCHAIN=0
//进入webrtc/src文件夹
cd src
gn gen --ide=vs out/Default
gn相关命令参数如下:
GN optionally generates files for IDE. Possibilities for <ide options>
--ide=<ide_name>
Generate files for an IDE. Currently supported values:
"eclipse" - Eclipse CDT settings file.
"vs" - Visual Studio project/solution files.
(default Visual Studio version: 2017)
"vs2013" - Visual Studio 2013 project/solution files.
"vs2015" - Visual Studio 2015 project/solution files.
"vs2017" - Visual Studio 2017 project/solution files.
"vs2019" - Visual Studio 2019 project/solution files.
"xcode" - Xcode workspace/solution files.
"qtcreator" - QtCreator project files.
"json" - JSON file containing target information
--filters=<path_prefixes>
Semicolon-separated list of label patterns used to limit the set of
generated projects (see "gn help label_pattern"). Only matching targets
and their dependencies will be included in the solution. Only used for
Visual Studio, Xcode and JSON.
--sln=<file_name>
Override default sln file name ("all"). Solution file is written to the
root build directory.
--no-deps
Don't include targets dependencies to the solution. Changes the way how
--filters option works. Only directly matching targets are included.
--winsdk=<sdk_version>
Use the specified Windows 10 SDK version to generate project files.
As an example, "10.0.15063.0" can be specified to use Creators Update SDK
instead of the default one.
--ninja-extra-args=<string>
This string is passed without any quoting to the ninja invocation
command-line. Can be used to configure ninja flags, like "-j".
如果需要清理工程:
gn clean out/Debug
ninja -C out/Default
在生成VS工程文件时,产生了如下报错:
D:\webrtc\webrtc\src>gn gen --ide=vs2019 out/Default
Traceback (most recent call last):
File "D:/webrtc/webrtc/src/build/toolchain/win/setup_toolchain.py", line 315, in <module>
main()
File "D:/webrtc/webrtc/src/build/toolchain/win/setup_toolchain.py", line 273, in main
env = _LoadToolchainEnv(cpu, toolchain_root, win_sdk_path, target_store)
File "D:/webrtc/webrtc/src/build/toolchain/win/setup_toolchain.py", line 189, in _LoadToolchainEnv
return _ExtractImportantEnvironment(variables)
File "D:/webrtc/webrtc/src/build/toolchain/win/setup_toolchain.py", line 67, in _ExtractImportantEnvironment
raise Exception(
Exception: Path "C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\shared" from environment variable "include" does not exist. Make sure the necessary SDK is installed.
ERROR at //build/toolchain/win/toolchain.gni:493:24: Script returned non-zero exit code.
win_toolchain_data = exec_script("//build/toolchain/win/setup_toolchain.py",
^----------
Current dir: D:/webrtc/webrtc/src/out/Default/
Command: D:/webrtc/depot_tools/bootstrap-2@3_8_10_chromium_23_bin/python3/bin/python3.exe D:/webrtc/webrtc/src/build/toolchain/win/setup_toolchain.py "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community" "C:\Program Files (x86)\Windows Kits\10" "C:\Windows\System32;C:\Windows\SysWOW64;Arm64Unused" win x86 environment.x86
Returned 1.
See //build/toolchain/win/BUILD.gn:34:3: whence it was called.
win_toolchains("x86") {
^-----------------------
See //BUILD.gn:39:3: which caused the file to be included.
group("default") {
^------------------
这里尝试了很多方法,最后才看懂可能由于webrtc版本问题需要10.0.22621.0的SDK。而VS2019中可以提供的只到10.0.22000.0,去Windows官网下载10.0.22621.0又显示不支持WIN10专业版,故最后在VS2022的修改中获得了10.0.22621.0的SDK并安装其SDK调试工具,才解决了此问题。