windows10下編譯32位和64位webrtc(m77)靜態庫

never715發表於2023-05-08

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. 編譯流程

  1. 檢出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
    ...
    
  2. 配置編譯引數

    gn args out\m77
    

    在彈出的 out\m77\args.gn 文字檔案中輸入編譯引數,或者直接以命令列引數形式攜帶。

  3. 生成ninja編譯指令碼,並生成vs2017工程檔案

    gn gen out\m77 --ide=vs2017
    
  4. 使用ninja編譯,將過程日誌記錄到檔案

    ninja -C out\m77 -d stats >> out\m77\comp.log
    

1.3. 先說遇到的問題

  1. 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步。

  2. 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步。

  3. 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步。

  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>

  5. 無法解析的外部符號 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.lib

1.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 resulePath=E:\google\webrtc\include

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的標頭檔案會以源目錄結構形式複製到目標路徑下。

有關robocopy的使用,參考robocopy

相關文章