当前位置:   article > 正文

ubuntu 18.04 Build WebRTC_webrtc m100

webrtc m100

背景

时隔两年多,现在又要搞 webrtc 了,翻出了原来写的文档按照流程操作,发现已经不能正常进行下去了,折腾了一番以后,重新记录下 Linux 下编译 webrtc 遇到的一些坑。

源码下载

webrtc 官方文档:Development | WebRTC

关于源码的下载大家都知道,现在下载越来越难搞。

分支切换

chrome 的分支管理跟我们的方式不一样,比如最近发布的 stable 100 对应的 M100 tag,如果要切换到这个稳定分支,还是需要找到其对应的 commit ID 的,可以从以下这个网址找到每个版本的分支和tag 的对应关系:

https://chromiumdash.appspot.com/branches

example

编译

主要的问题还是编译,如果按照官方文档一步步操作,只要下载成功,基本不会失败,但是在 Linux 下 webrtc 默认使用 clang 进行代码的检查和编译,虽然官方提供了切换 g++ 的命令参数,但是其也明确说了,仅仅是个切换 g++ 的命令参数而已,不保证没有问题看。

由于别人引用webrtc 的工程均使用 g++,同时为了避免引用动态库带来的性能回退,决定还是编译链接 webrtc 静态库,那么便不得不用 g++ 编译webrtc static library。

直接说结论:

Linux 下编译必须使用 g++-8 的版本,g++-7 和 g++-9 都不行,每个版本对代码的检查标准不一样,当然也可以通过修改源码适配编译器版本解决,但是代码量巨大,不确定需要修改多少;

同时使用 g++-8 编译的不能编译其测试程序,测试程序中语法补严谨,有很多warning as error,当然如果需要也可以一一解决。

本人此时的环境和版本分别是:

  • Ubuntu 18.04
  • g++-8.x
  • webrtc: M100
  1. mkdir -p /home/gobert/opensource/webrtc
  2. cd /home/gobert/opensource/webrtc
  3. git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
  4. export PATH=$PWD/depot_tools:$PATH
  5. fetch --nohooks webrtc
  6. # 切换到 M100 版本
  7. git checkout branch-heads/4896
  8. gclient sync
  9. bash build/install-build-deps.sh
  10. #如果提示该错误
  11. apt install pkg-config
  12. gn gen out/Debug --args='is_debug=true target_os="linux" target_cpu="x64" is_component_build=false use_sysroot=false is_clang=false use_lld=false treat_warnings_as_errors=false rtc_include_tests=false rtc_build_examples=false use_custom_libcxx=false use_rtti=true'
  13. ninja -C out/Debug
  14. # 编译 release 版
  15. gn gen out/Release gn gen out/Release --args='target_os="linux" target_cpu="x64" is_debug=false is_component_build=false use_sysroot=false is_clang=false use_lld=false treat_warnings_as_errors=false rtc_include_tests=false rtc_build_examples=false use_custom_libcxx=false use_rtti=true'
  16. ninja -C out/Release

几个有用的参数介绍:

is_debug 用于控制是否编译 debug 版本,如果 debug 版本还需要 link asan 的话,需要在 is_debug 为 true 的前提下,加上 is_asan=true;

is_clang=false 就是用来控制禁止 clang,使用 g++ 的;

treat_warnings_as_errors=false 使用 g++ 避免 warn as error 导致编译报错;

use_custom_libcxx=false 禁用webrtc 内部自定义的 libcxx,因为我这里是要编译静态库,如果使用其内部的 libcxx,外部使用系统自带的 libcxx,结果你想?

use_rtti=true 配置全局 rtti 统一为 true;

如果想要生成 compile_comands.json 用来配置 IDE 方便索引代码的话,就加上 –export-compile-commands 参数,注意该命令不在 –args 中,同时该参数仅支持 clang 编译器。

GitHub 分享

一个不错的下载部署环境的方案,一直都在更新:

GitHub - shiguredo-webrtc-build/webrtc-build: 様々な環境向けの WebRTC のビルドを行って、そのバイナリを提供しています

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/850937
推荐阅读
相关标签
  

闽ICP备14008679号