Skip to content

Instantly share code, notes, and snippets.

@aliforever
Created February 1, 2026 21:40
Show Gist options
  • Select an option

  • Save aliforever/045ce51621665fe96f4a0614a4e3a95f to your computer and use it in GitHub Desktop.

Select an option

Save aliforever/045ce51621665fe96f4a0614a4e3a95f to your computer and use it in GitHub Desktop.
Building libwebrtc for Windows/Qt Projects

Building libwebrtc for Windows/Qt Projects

This document describes the tools, requirements, and patches needed to build libwebrtc from source on Windows for Qt project integration.


Prerequisites

Required Tools

Tool Version Purpose
Visual Studio 2022/2026 Community+ C++ compiler (MSVC cl.exe)
Git Latest Source control
Python 3.x Build scripts
depot_tools Latest Google's build toolchain

Visual Studio Components

Install via Visual Studio Installer:

  • Desktop development with C++
  • C++ Clang tools for Windows (for clang-cl)
  • Windows 10/11 SDK

Environment Setup

1. Install depot_tools

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
set PATH=%PATH%;C:\path\to\depot_tools

2. Set Environment Variables

set DEPOT_TOOLS_WIN_TOOLCHAIN=0

IMPORTANT: DEPOT_TOOLS_WIN_TOOLCHAIN=0 forces use of local MSVC toolchain instead of Google's internal toolchain.


Fetch WebRTC Source

mkdir webrtc_checkout
cd webrtc_checkout
fetch --nohooks webrtc
gclient sync

Download is ~20GB. This may take 1-2 hours depending on connection speed.


Patches Required

Patch 1: Visual Studio 2026 Support

File: src/build/vs_toolchain.py

Add VS 2026 to supported versions:

MSVS_VERSIONS = {
    '2022': 'toolchain_is_2022',
    '2026': 'toolchain_is_2022',  # Added
}

MSVC_TOOLSET_VERSION = {
    # ...
    'VC145': 'VC145',  # Added for VS 2026
}

MSVS_FOLDER_NAMES = {
    '2022': '2022',
    '2026': '18',  # Added
}

Patch 2: Dynamic CRT for Qt Compatibility

File: src/build/config/win/BUILD.gn

Problem: WebRTC defaults to /MT (static CRT), Qt uses /MD (dynamic CRT).

Solution (around line 527):

config("default_crt") {
  if (is_component_build) {
    configs = [ ":dynamic_crt" ]
  } else {
    if (current_os == "winuwp") {
      configs = [ ":dynamic_crt" ]
    } else {
-     # Desktop Windows: static CRT.
-     configs = [ ":static_crt" ]
+     # Desktop Windows: Use dynamic CRT for Qt compatibility.
+     configs = [ ":dynamic_crt" ]
    }
  }
}

Build Commands

Configure with GN

cd src
gn gen out/Release_ClangMSVC --args="is_debug=false rtc_include_tests=false treat_warnings_as_errors=false use_custom_libcxx=false use_rtti=true target_cpu=\"x64\""

Build Configuration Options

Argument Value Purpose
is_debug false Release build
rtc_include_tests false Skip test targets
treat_warnings_as_errors false Ignore warnings
use_custom_libcxx false Use MSVC STL instead of libc++
use_rtti true Enable RTTI for Qt compatibility
target_cpu "x64" 64-bit build

Build with Ninja

ninja -C out/Release_ClangMSVC webrtc

Build produces: out/Release_ClangMSVC/obj/webrtc.lib (~365 MB)


Integration with Qt Project

Copy Library and Headers

copy out\Release_ClangMSVC\obj\webrtc.lib C:\path\to\project\libs\webrtc\lib\
robocopy src\api libs\webrtc\include\api /E /XD tests test
robocopy src\rtc_base libs\webrtc\include\rtc_base /E /XD tests test
robocopy src\third_party\abseil-cpp\absl libs\webrtc\include\absl /E

CMakeLists.txt Configuration

if(MSVC)
    set(WEBRTC_ROOT "${CMAKE_SOURCE_DIR}/libs/webrtc")
    set(WEBRTC_LIBRARY "${WEBRTC_ROOT}/lib/webrtc.lib")
    
    add_compile_definitions(
        WEBRTC_WIN
        NOMINMAX
        WIN32_LEAN_AND_MEAN
    )
    
    target_link_libraries(${PROJECT_NAME} PRIVATE
        ${WEBRTC_LIBRARY}
        ws2_32 crypt32 secur32 winmm
        dmoguids wmcodecdspuuid amstrmid msdmo strmiids
        iphlpapi d3d11 dxgi
    )
endif()

Troubleshooting

RuntimeLibrary Mismatch (LNK2038)

Error: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease'

Cause: WebRTC built with /MT, project expects /MD.

Solution: Apply Patch 2 (dynamic CRT) and rebuild WebRTC.


compiler-rt Build Failures

Cause: Pure MSVC (is_clang=false) fails with compiler-rt.

Solution: Use clang-cl (default) with use_custom_libcxx=false.


CMake "unknown pragma 'clang'" Warnings

These are harmless warnings from WebRTC headers. They can be suppressed with:

if(MSVC)
    add_compile_options(/wd4068)  # Suppress unknown pragma
endif()

Version Compatibility Matrix

Component Tested Version
Windows 10/11
Visual Studio 2022, 2026
Qt 6.10.2
WebRTC m131+
OpenSSL 3.6.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment