写在前面的话
WebRTC 下载编译的困难想必都很清楚了。我试图写一篇尽可能详细的编译手册,旨在帮助大家减少不必要的时间浪费。
鉴于 WebRTC 更新太快,所以网上很多编译方法都失效了,所以如果你看到是几年前的文章,就没必要较真了。本文基于声网提供的国内镜像,写作时间为2019年10月16日,WebRTC 为2019年5月16日版本。诸君参考。
本文快速阅读方法
WebRTC 发展历史
WebRTC 的大名,在音视频领域的朋友想必都听过了。集音视频采集、编解码、传输、渲染于一身,其中音频降噪模块,尤为优秀。能看到这篇文章的,肯定也是准备研究一番了。不敢保证未来能否取代 Flash,成为浏览器端的统一解决方案,至少目前来看,是这样的。
安装编译
本文使用了声网提供的国内镜像,并主要参考了它的编译指南。但因为写的过于简略,笔者在编译时还是遇到了很多问题。所以,本文编写目的也是对其作一些补充说明。默认读者是小小小小白,高手请绕行。
准备条件
- Win7 及以上 64 位操作系统(笔者使用 Win10)
- 内存 8G 以上,当然越大越好
- 30G 以上的存储空间,不能是 FAT32 格式,因为会产生大于 4G 的文件。
Visual Studio 安装(如不需要,请忽略)
在 Windows 下开发,离不开宇宙第一 IDE——Vsiual Studio,即使网上有人说它不好用。WebRTC 的编译需要 2017 及以上版本,因为会用到 C++11、C++14 的很多新特性。安装时选择自定义安装,必须勾选如下几项:
- 10.0.17134 或以上的 Win10 SDK
- MFC 以及 ATL 这两项
其他根据需要选择。下图是我的安装选项

如果 VS 版本过低,找不到 10.0.17134,则需要手动下载安装包下载地址。我在这里浪费了很多时间。
安装完 VS2017 后,必须安装 SDK 调试工具。打开控制面板->程序与功能,找到刚才安装的 Windows Software Development Kit,鼠标右键->change

勾选 Debugging Tools For Windows,然后点击 change。

以下部分严重学习了声网的教程(原文地址)。同时,考虑到声网可能会有更新,所以我只做一些必要的补充。以下配置通过 cmd 命令窗口输入,注意使用管理员权限。
环境配置
-
配置 gitlab 账号。注意,是gitlab账号,不是 github 账号。
1 2
|
git config --global user.email "email@email.com" git config --global user.name "username"
|
-
设置 VS 编译的环境变量
1 2 3
|
set GYP_MSVS_VERSION=2017 set GYP_MSVS_OVERRIDE_PATH=D:Program Files (x86)Microsoft Visual Studio2017Community set GYP_GENERATORS=msvs-ninja,ninja
|
其中GYP_MSVS_OVERRIDE_PATH
是我们安装的 VS2017 路径。
-
替换 git 镜像仓库地址
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
git config --global url.http://120.92.49.206:3232/chromiumsrc/webrtc.git.insteadOf https://chromium.googlesource.com/external/webrtc.git git config --global url.http://120.92.49.206:3232/chromiumsrc/base.git.insteadOf https://chromium.googlesource.com/chromium/src/base git config --global url.http://120.92.49.206:3232/chromiumsrc/build.git.insteadOf https://chromium.googlesource.com/chromium/src/build git config --global url.http://120.92.49.206:3232/chromiumsrc/buildtools.git.insteadOf https://chromium.googlesource.com/chromium/src/buildtools git config --global url.http://120.92.49.206:3232/chromiumsrc/gradle.git.insteadOf https://chromium.googlesource.com/external/github.com/gradle/gradle.git git config --global url.http://120.92.49.206:3232/chromiumsrc/ios.git.insteadOf https://chromium.googlesource.com/chromium/src/ios.git git config --global url.http://120.92.49.206:3232/chromiumsrc/testing.git.insteadOf https://chromium.googlesource.com/chromium/src/testing git config --global url.http://120.92.49.206:3232/chromiumsrc/third_party.git.insteadOf https://chromium.googlesource.com/chromium/src/third_party git config --global url.http://120.92.49.206:3232/chromiumsrc/clang-format.git.insteadOf https://chromium.googlesource.com/chromium/llvm-project/cfe/tools/clang-format.git git config --global url.http://120.92.49.206:3232/chromiumsrc/libcxx.git.insteadOf https://chromium.googlesource.com/chromium/llvm-project/libcxx.git git config --global url.http://120.92.49.206:3232/chromiumsrc/libcxxabi.git.insteadOf https://chromium.googlesource.com/chromium/llvm-project/libcxxabi.git git config --global url.http://120.92.49.206:3232/chromiumsrc/libunwind.git.insteadOf https://chromium.googlesource.com/external/llvm.org/libunwind.git git config --global url.http://120.92.49.206:3232/chromiumsrc/android_ndk.git.insteadOf https://chromium.googlesource.com/android_ndk.git git config --global url.http://120.92.49.206:3232/chromiumsrc/android_tools.git.insteadOf https://chromium.googlesource.com/android_tools.git git config --global url.http://120.92.49.206:3232/chromiumsrc/auto.git.insteadOf https://chromium.googlesource.com/external/github.com/google/auto.git git config --global url.http://120.92.49.206:3232/chromiumsrc/catapult.git.insteadOf https://chromium.googlesource.com/catapult.git git config --global url.http://120.92.49.206:3232/chromiumsrc/compact_enc_det.git.insteadOf https://chromium.googlesource.com/external/github.com/google/compact_enc_det.git git config --global url.http://120.92.49.206:3232/chromiumsrc/colorama.git.insteadOf https://chromium.googlesource.com/external/colorama.git git config --global url.http://120.92.49.206:3232/chromiumsrc/depot_tools.git.insteadOf https://chromium.googlesource.com/chromium/tools/depot_tools.git git config --global url.http://120.92.49.206:3232/chromiumsrc/errorprone.git.insteadOf https://chromium.googlesource.com/chromium/third_party/errorprone.git git config --global url.http://120.92.49.206:3232/chromiumsrc/ffmpeg.git.insteadOf https://chromium.googlesource.com/chromium/third_party/ffmpeg.git git config --global url.http://120.92.49.206:3232/chromiumsrc/findbugs.git.insteadOf https://chromium.googlesource.com/chromium/deps/findbugs.git git config --global url.http://120.92.49.206:3232/chromiumsrc/freetype2.git.insteadOf https://chromium.googlesource.com/chromium/src/third_party/freetype2.git git config --global url.http://120.92.49.206:3232/chromiumsrc/harfbuzz.git.insteadOf https://chromium.googlesource.com/external/github.com/harfbuzz/harfbuzz.git git config --global url.http://120.92.49.206:3232/chromiumsrc/gtest-parallel.git.insteadOf https://chromium.googlesource.com/external/github.com/google/gtest-parallel git config --global url.http://120.92.49.206:3232/chromiumsrc/googletest.git.insteadOf https://chromium.googlesource.com/external/github.com/google/googletest.git git config --global url.http://120.92.49.206:3232/chromiumsrc/icu.git.insteadOf https://chromium.googlesource.com/chromium/deps/icu.git git config --global url.http://120.92.49.206:3232/chromiumsrc/jsr-305.git.insteadOf https://chromium.googlesource.com/external/jsr-305.git git config --global url.http://120.92.49.206:3232/chromiumsrc/jsoncpp.git.insteadOf https://chromium.googlesource.com/external/github.com/open-source-parsers/jsoncpp.git git config --global url.http://120.92.49.206:3232/chromiumsrc/junit.git.insteadOf https://chromium.googlesource.com/external/junit.git git config --global url.http://120.92.49.206:3232/chromiumsrc/fuzzer.git.insteadOf https://chromium.googlesource.com/chromium/llvm-project/compiler-rt/lib/fuzzer.git git config --global url.http://120.92.49.206:3232/chromiumsrc/libjpeg_turbo.git.insteadOf https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git git config --global url.http://120.92.49.206:3232/chromiumsrc/libsrtp.git.insteadOf https://chromium.googlesource.com/chromium/deps/libsrtp.git git config --global url.http://120.92.49.206:3232/chromiumsrc/libvpx.git.insteadOf https://chromium.googlesource.com/webm/libvpx.git git config --global url.http://120.92.49.206:3232/chromiumsrc/libyuv.git.insteadOf https://chromium.googlesource.com/libyuv/libyuv.git git config --global url.http://120.92.49.206:3232/chromiumsrc/linux-syscall-support.git.insteadOf https://chromium.googlesource.com/linux-syscall-support.git git config --global url.http://120.92.49.206:3232/chromiumsrc/mockito.git.insteadOf https://chromium.googlesource.com/external/mockito/mockito.git git config --global url.http://120.92.49.206:3232/chromiumsrc/nasm.git.insteadOf https://chromium.googlesource.com/chromium/deps/nasm.git git config --global url.http://120.92.49.206:3232/chromiumsrc/openh264.git.insteadOf https://chromium.googlesource.com/external/github.com/cisco/openh264 git config --global url.http://120.92.49.206:3232/chromiumsrc/requests.git.insteadOf https://chromium.googlesource.com/external/github.com/kennethreitz/requests.git git config --global url.http://120.92.49.206:3232/chromiumsrc/robolectric.git.insteadOf https://chromium.googlesource.com/external/robolectric.git git config --global url.http://120.92.49.206:3232/chromiumsrc/ub-uiautomator.git.insteadOf https://chromium.googlesource.com/chromium/third_party/ub-uiautomator.git git config --global url.http://120.92.49.206:3232/chromiumsrc/usrsctp.git.insteadOf https://chromium.googlesource.com/external/github.com/sctplab/usrsctp git config --global url.http://120.92.49.206:3232/chromiumsrc/binaries.git.insteadOf https://chromium.googlesource.com/chromium/deps/yasm/binaries.git git config --global url.http://120.92.49.206:3232/chromiumsrc/patched-yasm.git.insteadOf https://chromium.googlesource.com/chromium/deps/yasm/patched-yasm.git git config --global url.http://120.92.49.206:3232/chromiumsrc/tools.git.insteadOf https://chromium.googlesource.com/chromium/src/tools git config --global url.http://120.92.49.206:3232/chromiumsrc/client-py.git.insteadOf https://chromium.googlesource.com/infra/luci/client-py.git git config --global url.http://120.92.49.206:3232/chromiumsrc/boringssl.git.insteadOf https://boringssl.googlesource.com/boringssl.git
|
-
原文命令是在 Linux 环境下,有些命令 Windows 不可用,比如export
、chmod
、rm
等。所以我只用了以下的命令。新建一个工作目录 webrtc。
1 2 3 4 5
|
cd webrtc git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
cd depot_tools git checkout gitlab
|
-
手动设置环境变量,将 depot_tools 目录添加到 Path,并移动到最上面。

同步 WebRTC
-
在 depot_tools 文件夹同级目录创建 code 文件夹,并执行以下命令。
1 2 3 4 5 6 7 8 9 10
|
cd code
gclient config --name src https://chromium.googlesource.com/external/webrtc.git@gitlab
set CDS_CLANG_BUCKET_OVERRIDE=http://120.92.49.206:3232/chromiumsrc/commondatastorage/raw/master/public/chromium-browser-clang
<!--告诉depot_tools使用我们本机的VS进行编译--> set DEPOT_TOOLS_WIN_TOOLCHAIN=0
gclient sync --patch-ref=https://chromium.googlesource.com/chromium/src/build.git@gitlab
|
这一步会花费很长的时间,期间可能会报错,比如 ‘tar’ 不是内部或外部命令,也不是可运行的程序,找到工具所在目录,并添加到环境变量 path 里面,重启一下电脑。然后再执行一次gclient sync
命令。
编译
-
进入 webrtc/src 文件夹
1 2
|
cd src gn gen --ide=vs out/Default
|
此时,我们在 out 文件夹,就能看到久违的 all.sln 文件了。欣赏一下吧。

GN 命令参数如下(原文地址)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
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.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
--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".
|
比如:
1
|
gn gen --ide=vs2017 --winsdk=10.0.17134.0 out/Default
|
-
使用 ninja 编译
常见错误及解决办法
-
同步代码时,Exception: C:ProgramDataMicrosoftWindowsStart MenuProgramsVCvcvarsall.bat is missing - make sure VC++ tools are installed
解决方法:没有安装 Debugging Tools for Windows(参考 2.2)
-
同步代码时,遇到各种 “不是内部或外部命令,也不是可运行的程序”
解决方法:找到工具所在目录,并添加到环境变量 path 里面,重启一下电脑
-
使用 VS 编译时,unknown type name ‘KSJACK DESCRIPTION’; did you mean ‘SERVICE_DESCRIPTION’
解决方法:安装 10.0.17134 或以上的 Win10 SDK(参考 2.2),并重新执行gn gen --ide=vs out/Default
命令。
致谢
再次感谢声网提供的资源
其他参考链接: