windows10下编译32位和64位webrtc(m77)静态库
1. windows10下编译32位和64位webrtc(m77)静态库
省略挂代理下载depot_tools以及webrtc代码的过程。。。
可参考webrtc编译
务必在 cmd
终端环境下进入到 webrtc\src
目录,再执行以下操作!
1.1. 环境配置
- 在系统环境变量下编辑PATH,将depot_tools所在路径放在PATH变量最前面。
- 设置环境变量
DEPOT_TOOLS_WIN_TOOLCHAIN=0
1.2. 编译流程
-
检出m77版本的webrtc
git checkout -b m77 remotes/branch-heads/m77
gclient sync -D
m77版本对应详情:
commit ad73985e75684cb4ac4dadb9d3d86ad0d66612a0 (HEAD -> m77, branch-heads/m77) Author: Henrik Bostr?m <hbos@webrtc.org> Date: Wed Aug 21 12:09:51 2019 +0200 Add implemented-but-missing members to RTCMediaStreamTrackStats::Members ...
-
配置编译参数
gn args out\m77
在弹出的
out\m77\args.gn
文本文件中输入编译参数,或者直接以命令行参数形式携带。 -
生成ninja编译脚本,并生成vs2017工程文件
gn gen out\m77 --ide=vs2017
-
使用ninja编译,将过程日志记录到文件
ninja -C out\m77 -d stats >> out\m77\comp.log
1.3. 先说遇到的问题
-
ImportError: No module named win32file
[236/2777] LIB obj/media/rtc_constants.lib FAILED: obj/media/rtc_constants.lib e:/google/depot_tools/bootstrap-2@3_8_10_chromium_23_bin/python/bin/python.exe ../../build/toolchain/win/tool_wrapper.py link-wrapper environment.x64 False lib.exe /nologo /ignore:4221 /OUT:obj/media/rtc_constants.lib @obj/media/rtc_constants.lib.rsp Traceback (most recent call last): File "../../build/toolchain/win/tool_wrapper.py", line 31, in <module> import win32file # pylint: disable=import-error ImportError: No module named win32file [237/2777] CXX obj/logging/rtc_stream_config/rtc_stream_config.obj
参考Build issue with M76 version of webrtc on Windows
使用以下命令
python -m pip install pywin32
最好保证系统环境变量路径中没有其他版本的python影响。
然后继续执行编译流程中第4步。
-
fatal error C1189: #error: "See: bugs.webrtc.
这个问题在编译参数
is_clang=false
时才会出现[1210/2535] CXX obj/modules/video_coding/webrtc_h264/h264_encoder_impl.obj FAILED: obj/modules/video_coding/webrtc_h264/h264_encoder_impl.obj ... E:\google\webrtc\src\modules/video_coding/codecs/h264/h264_encoder_impl.h(21): fatal error C1189: #error: "See: bugs.webrtc.org/9213#c13."
注释掉该行之后继续执行编译流程中第4步,发现后续还会出现类似的报错
E:\google\webrtc\src\modules/video_coding/codecs/h264/h264_color_space.h(20): fatal error C1189: #error: "See: bugs.webrtc.org/9213#c13."
E:\google\webrtc\src\modules/video_coding/codecs/h264/h264_decoder_impl.h(21): fatal error C1189: #error: "See: bugs.webrtc.org/9213#c13."
,所以一次性注释掉三个文件中将会报错的行:
See: bugs.webrtc.org/9213#c13.
- modules/video_coding/codecs/h264/h264_decoder_impl.h(21)
- modules/video_coding/codecs/h264/h264_encoder_impl.h(21)
- modules/video_coding/codecs/h264/h264_color_space.h(20)
然后继续执行编译流程中第4步。
-
error C2059: 语法错误:“字符串”
[13/1314] CC obj/third_party/ffmpeg/ffmpeg_internal/pcm.obj FAILED: obj/third_party/ffmpeg/ffmpeg_internal/pcm.obj ... ../../third_party/ffmpeg/libavcodec/pcm.c(629): error C2059: 语法错误:“字符串”
同样注释掉报错这一行,然后继续执行编译流程中第4步。
-
关于应用程序在webrtc.lib链接静态库时报错
Linker can't find CreatePeerConnectionFactory after M77 update
修改方法
148073: Add missing dependencies to the static library
然后重新生成会增加:create_peerconnection_factory.lib
同时更新:webrtc.lib再次编译后报另外的连接错误:
1>webrtc.lib(http_common.obj) : error LNK2019: 无法解析的外部符号 _AcquireCredentialsHandleA@36,该符号在函数 "enum rtc::HttpAuthResult... 中被引用 1>webrtc.lib(http_common.obj) : error LNK2019: 无法解析的外部符号 __imp__FreeCredentialsHandle@4,该符号在函数 "public: virtual __thiscall rtc::`anonymous namespace'::NegotiateAuthContext::~NegotiateAuthContext(void)"... 中被引用 1>webrtc.lib(http_common.obj) : error LNK2019: 无法解析的外部符号 _InitializeSecurityContextA@48,该符号在函数 "enum rtc::HttpAuthResult... 中被引用 1>webrtc.lib(http_common.obj) : error LNK2019: 无法解析的外部符号 _CompleteAuthToken@8,该符号在函数 "enum rtc::HttpAuthResult __cdecl rtc::HttpAuthenticate... 中被引用 1>webrtc.lib(http_common.obj) : error LNK2019: 无法解析的外部符号 __imp__DeleteSecurityContext@4,该符号在函数 "public: virtual __thiscall rtc::`anonymous namespace'::NegotiateAuthContext::~NegotiateAuthContext(void)"... 中被引用 1>... : fatal error LNK1120: 5 个无法解析的外部命令
解决方法:
链接依赖库中增加Secur32.lib
微软的解释:包含了security.h的头文件要加#pragma comment(lib,"Secur32.lib")
AcquireCredentialsHandleA function (sspi.h)在这两个文件中都有对security.h的引用:
rtc_base/http_common.cc:19:#include <security.h>
rtc_base/socket_adapters.cc:27:#include <security.h>
-
无法解析的外部符号 avpriv_emms_asm
这个问题在
is_clang=false
编译64位库之后链接webrtc静态库时出现虽然生成了webrtc.lib,但在应用程序或者dll在链接webrtc时会报错
4> 正在创建库 ... 和对象 ... 4>webrtc.lib(autorename_libavcodec_utils.obj) : error LNK2019: 无法解析的外部符号 avpriv_emms_asm,该符号在函数 avcodec_default_execute 中被引用 4>webrtc.lib(decode.obj) : error LNK2001: 无法解析的外部符号 avpriv_emms_asm 4>webrtc.lib(vp3.obj) : error LNK2001: 无法解析的外部符号 avpriv_emms_asm 4>webrtc.lib(pcm.obj) : error LNK2001: 无法解析的外部符号 avpriv_emms_asm 4>E:\gitlab\sdk\zkms_client\build-win64\sdk\Debug\zkmsclient.dll : fatal error LNK1120: 1 个无法解析的外部命令
根据网上有限的资料显示,可能是X64不支持大多数汇编指令,webrtc源码的第三方目录ffmpeg里面有汇编代码。用clang编译没这个问题,但是clang编译的库vc不能引用。只能替换ffmpeg源码或者在windows上编译 好ffmpeg,然后将ffmpeg的include和lib文件添加到webrtc项目。
但是笔者后来使用clang编译的库在vc下仍能正常使用。
参考:
webrtc 支持openh264
在win10上编译webRTC(问题篇)
windows上编译webrtc_m84支持h.264编解码遇到的问题总结
webrtc 4577 version Build error,unresoved symbol avpriv_emms_asm, build with vs2017,x64
1.4. 编译参数
在 gn args out\m77
命令执行之后弹出的文本文件中就是编译时需要的所有参数,关于全部参数及说明可以使用命令 gn args out\m77 --list
查看。
1.4.1. 32位编译参数示例
# Build arguments go here.
# See "gn args <out_dir> --list" for available build arguments.
is_clang = true
is_debug = true
proprietary_codecs = true
rtc_build_examples = false
rtc_build_tools = false
rtc_include_internal_audio_device = false
rtc_include_pulse_audio = false
rtc_include_tests = false
rtc_libvpx_build_vp9 = false
rtc_use_gtk = false
rtc_use_h264 = true
target_cpu = "x86"
treat_warnings_as_errors = false
use_aura = false
use_custom_libcxx = false
use_gold = true
use_lld = false
use_ozone = true
use_rtti = true
1.4.2. 64位编译参数示例
只需将上述 target_cpu
的值换成 "x64"
即可。
1.5. 生成目标
如果一切顺利,最终生成一大堆lib文件,实际上我们只需要 webrtc.lib
文件足矣。
展开/折叠
out/m77/obj/api/audio_codecs/builtin_audio_decoder_factory.lib out/m77/obj/api/audio_codecs/builtin_audio_encoder_factory.lib out/m77/obj/api/audio_codecs/g711/audio_decoder_g711.lib out/m77/obj/api/audio_codecs/g711/audio_encoder_g711.lib out/m77/obj/api/audio_codecs/g722/audio_decoder_g722.lib out/m77/obj/api/audio_codecs/g722/audio_encoder_g722.lib out/m77/obj/api/audio_codecs/ilbc/audio_decoder_ilbc.lib out/m77/obj/api/audio_codecs/ilbc/audio_encoder_ilbc.lib out/m77/obj/api/audio_codecs/isac/audio_decoder_isac_float.lib out/m77/obj/api/audio_codecs/isac/audio_encoder_isac_float.lib out/m77/obj/api/audio_codecs/L16/audio_decoder_L16.lib out/m77/obj/api/audio_codecs/L16/audio_encoder_L16.lib out/m77/obj/api/audio_codecs/opus/audio_decoder_multiopus.lib out/m77/obj/api/audio_codecs/opus/audio_decoder_opus.lib out/m77/obj/api/audio_codecs/opus/audio_encoder_opus_config.lib out/m77/obj/api/libjingle_peerconnection_api.lib out/m77/obj/api/transport/goog_cc.lib out/m77/obj/api/transport/network_control.lib out/m77/obj/api/video/builtin_video_bitrate_allocator_factory.lib out/m77/obj/api/video_codecs/builtin_video_decoder_factory.lib out/m77/obj/api/video_codecs/builtin_video_encoder_factory.lib out/m77/obj/api/video_codecs/rtc_software_fallback_wrappers.lib out/m77/obj/api/video_codecs/vp8_temporal_layers_factory.lib out/m77/obj/audio/audio.lib out/m77/obj/audio/utility/audio_frame_operations.lib out/m77/obj/call/call.lib out/m77/obj/common_audio/common_audio.lib out/m77/obj/common_audio/common_audio_sse2.lib out/m77/obj/common_video/common_video.lib out/m77/obj/logging/rtc_event_log_impl_encoder.lib out/m77/obj/media/rtc_audio_video.lib out/m77/obj/media/rtc_constants.lib out/m77/obj/media/rtc_data.lib out/m77/obj/media/rtc_encoder_simulcast_proxy.lib out/m77/obj/media/rtc_internal_video_codecs.lib out/m77/obj/media/rtc_media_base.lib out/m77/obj/media/rtc_simulcast_encoder_adapter.lib out/m77/obj/modules/audio_coding/audio_coding.lib out/m77/obj/modules/audio_coding/audio_coding_opus_common.lib out/m77/obj/modules/audio_coding/audio_encoder_cng.lib out/m77/obj/modules/audio_coding/audio_network_adaptor.lib out/m77/obj/modules/audio_coding/audio_network_adaptor_config.lib out/m77/obj/modules/audio_coding/g711.lib out/m77/obj/modules/audio_coding/g722.lib out/m77/obj/modules/audio_coding/ilbc.lib out/m77/obj/modules/audio_coding/isac.lib out/m77/obj/modules/audio_coding/isac_c.lib out/m77/obj/modules/audio_coding/isac_common.lib out/m77/obj/modules/audio_coding/legacy_encoded_audio_frame.lib out/m77/obj/modules/audio_coding/neteq.lib out/m77/obj/modules/audio_coding/pcm16b.lib out/m77/obj/modules/audio_coding/webrtc_cng.lib out/m77/obj/modules/audio_coding/webrtc_multiopus.lib out/m77/obj/modules/audio_coding/webrtc_opus.lib out/m77/obj/modules/audio_mixer/audio_frame_manipulator.lib out/m77/obj/modules/audio_mixer/audio_mixer_impl.lib out/m77/obj/modules/audio_processing/aec3/aec3.lib out/m77/obj/modules/audio_processing/audio_buffer.lib out/m77/obj/modules/audio_processing/audio_processing.lib out/m77/obj/modules/audio_processing/config.lib out/m77/obj/modules/audio_processing/vad/vad.lib out/m77/obj/modules/bitrate_controller/bitrate_controller.lib out/m77/obj/modules/congestion_controller/congestion_controller.lib out/m77/obj/modules/congestion_controller/goog_cc/goog_cc.lib out/m77/obj/modules/congestion_controller/rtp/transport_feedback.lib out/m77/obj/modules/desktop_capture/desktop_capture_differ_sse2.lib out/m77/obj/modules/desktop_capture/desktop_capture_generic.lib out/m77/obj/modules/desktop_capture/primitives.lib out/m77/obj/modules/pacing/pacing.lib out/m77/obj/modules/remote_bitrate_estimator/remote_bitrate_estimator.lib out/m77/obj/modules/rtp_rtcp/rtp_rtcp.lib out/m77/obj/modules/utility/utility.lib out/m77/obj/modules/video_capture/video_capture_module.lib out/m77/obj/modules/video_coding/encoded_frame.lib out/m77/obj/modules/video_coding/nack_module.lib out/m77/obj/modules/video_coding/packet.lib out/m77/obj/modules/video_coding/video_coding.lib out/m77/obj/modules/video_coding/webrtc_h264.lib out/m77/obj/modules/video_coding/webrtc_multiplex.lib out/m77/obj/modules/video_coding/webrtc_vp8.lib out/m77/obj/modules/video_coding/webrtc_vp8_temporal_layers.lib out/m77/obj/modules/video_coding/webrtc_vp9.lib out/m77/obj/modules/video_coding/webrtc_vp9_helpers.lib out/m77/obj/modules/video_processing/video_processing.lib out/m77/obj/modules/video_processing/video_processing_sse2.lib out/m77/obj/p2p/libstunprober.lib out/m77/obj/p2p/rtc_p2p.lib out/m77/obj/pc/peerconnection.lib out/m77/obj/pc/rtc_pc_base.lib out/m77/obj/rtc_base/experiments/alr_experiment.lib out/m77/obj/rtc_base/experiments/audio_allocation_settings.lib out/m77/obj/rtc_base/experiments/balanced_degradation_settings.lib out/m77/obj/rtc_base/experiments/cpu_speed_experiment.lib out/m77/obj/rtc_base/experiments/field_trial_parser.lib out/m77/obj/rtc_base/experiments/jitter_upper_bound_experiment.lib out/m77/obj/rtc_base/experiments/keyframe_interval_settings_experiment.lib out/m77/obj/rtc_base/experiments/normalize_simulcast_size_experiment.lib out/m77/obj/rtc_base/experiments/quality_scaler_settings.lib out/m77/obj/rtc_base/experiments/quality_scaling_experiment.lib out/m77/obj/rtc_base/experiments/rate_control_settings.lib out/m77/obj/rtc_base/experiments/rtt_mult_experiment.lib out/m77/obj/rtc_base/rtc_base.lib out/m77/obj/rtc_base/rtc_numerics.lib out/m77/obj/rtc_base/weak_ptr.lib out/m77/obj/stats/rtc_stats.lib out/m77/obj/system_wrappers/system_wrappers.lib out/m77/obj/third_party/boringssl/boringssl.lib out/m77/obj/third_party/boringssl/boringssl_asm.lib out/m77/obj/third_party/ffmpeg/ffmpeg_internal.lib out/m77/obj/third_party/ffmpeg/ffmpeg_nasm.lib out/m77/obj/third_party/libjpeg_turbo/libjpeg.lib out/m77/obj/third_party/libjpeg_turbo/simd.lib out/m77/obj/third_party/libjpeg_turbo/simd_asm.lib out/m77/obj/third_party/libsrtp/libsrtp.lib out/m77/obj/third_party/libvpx/libvpx.lib out/m77/obj/third_party/libvpx/libvpx_yasm.lib out/m77/obj/third_party/openh264/openh264_common_yasm.lib out/m77/obj/third_party/openh264/openh264_encoder_yasm.lib out/m77/obj/third_party/openh264/openh264_processing_yasm.lib out/m77/obj/third_party/opus/opus.lib out/m77/obj/third_party/pffft/pffft.lib out/m77/obj/third_party/usrsctp/usrsctp.lib out/m77/obj/third_party/yasm/yasm_utils.lib out/m77/obj/video/video.lib out/m77/obj/webrtc.lib out/m77/win_clang_x64/obj/third_party/libyuv/libyuv_internal.lib1.6. 提取头文件和库文件
1.6.1. 库文件提取
新建批处理文件 gen-webrtc-lib.bat
,键入以下内容。
echo off
:: 定义源目录
set sourcePath=E:\google\webrtc\src\out\m77\obj
:: 定义目标路径
set resulePath=E:\google\webrtc\lib
xcopy %sourcePath%\*.lib %resulePath%\ /s /c /y /h /r /f
pause
执行批处理文件 gen-webrtc-lib.bat
,webrtc的所有编译好的库文件会拷贝到目标路径下。
1.6.2. 头文件提取
新建批处理文件 gen-webrtc-inc.bat
,键入以下内容。
echo off
:: 定义源目录
set sourcePath=E:\google\webrtc\src
::set sourcePath=E:\google\depot_tools
:: 定义目标路径
set resulePath=E:\google\webrtc\include
::robocopy %sourcePath% %resulePath% *.bat *.cmd /s /log:robocopy-log.txt /xd .git bootstrap bootstrap-2@3_8_10_chromium_19_bin python
robocopy %sourcePath% %resulePath% *.h *.hpp *.hxx ^
/s /mt /log:robocopy-log.txt /fp /ndl ^
/xd ^
"%sourcePath%\.git" ^
"%sourcePath%\build" ^
"%sourcePath%\build_overrides" ^
"%sourcePath%\buildtools" ^
"%sourcePath%\data" ^
"%sourcePath%\examples" ^
"%sourcePath%\out" ^
"%sourcePath%\rtc_tools" ^
"%sourcePath%\resources" ^
"%sourcePath%\test" ^
"%sourcePath%\testing" ^
"%sourcePath%\tools" ^
"%sourcePath%\tools_webrtc" ^
"%sourcePath%\third_party\blink" ^
"%sourcePath%\third_party\depot_tools" ^
"%sourcePath%\third_party\catapult"
pause
执行批处理文件 gen-webrtc-inc.bat
,webrtc的头文件会以源目录结构形式拷贝到目标路径下。