Compiling ZLMediaKit on Windows 11

I previously built a lightweight GB28181 platform, but installing it required some familiarity with containers, which made the experience a bit inconvenient. So I decided to package it as a double-click-to-run application for end users. To achieve this, ZLMediaKit needs to be compiled on Windows.
This document explains how to compile ZLMediaKit on Windows 11.
During compilation following the official tutorial, I encountered several errors and found some parts of the documentation unclear. I felt it was necessary to write a supplementary guide.
Please follow the steps one by one.

1. Prerequisites

Before starting the build, make sure the following software is installed in your development environment:

  • Visual Studio: VS2022 (with the Desktop development with C++ workload installed).
  • Git: For cloning the repository.

I performed the build on Windows 11 with VS2022. You do not need to open VS2022 during the build process — only PowerShell and the x64 Native Tools Command Prompt for VS 2022 are needed.

2. Get the Source Code

Open a command-line tool (CMD or PowerShell) and run the following commands to clone the repository and initialize submodules:

1
2
3
4
5
6
7
8
# Clone the main repository
git clone https://github.com/ZLMediaKit/ZLMediaKit.git

# Enter the directory
cd ZLMediaKit

# Initialize submodules (important — the build will fail without this)
git submodule update --init --recursive

The code I compiled is from the latest master branch as of 2026/3/1.


3. Windows Build Using scoop + vcpkg

Note: The following is based on the ZLMediaKit official documentation for Windows compilation, with some modifications I made to ensure a successful build.

The following describes one way to compile ZLMediaKit using scoop + vcpkg.

  • scoop: A command-line package manager for Windows
  • vcpkg: A C++ library manager initiated by Microsoft, containing a large number of commonly used open-source libraries

Since both tools are command-line based, they integrate very well into automated workflows. Highly recommended.

⚠️ Note

  • All operations below must be performed in a PowerShell terminal unless otherwise specified.

4. Install Build Dependencies via scoop and vcpkg

4.1 Download and Install scoop, Then Install Dependency Tools

Note: Simply run the commands below directly in PowerShell. Errors are rare in this step.

The following installs the dependency tools cmake and ninja (optional but recommended). Skip this step if they are already installed.

For full details, refer to the official documentation. The following lists only the relevant brief steps:

  1. Set the SCOOP environment variable to configure the installation directory for scoop and the packages it manages:

    1
    $env:SCOOP = 'C:\work\develop\scoop'
  2. Allow PowerShell script execution for the current user:

    1
    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
  3. Install scoop:

    1
    iwr -useb get.scoop.sh | iex
  4. Add the extras bucket to scoop:

    1
    scoop bucket add extras
  5. Install cmake and ninja:

    1
    scoop install cmake ninja

💡 Tip: For convenience later, set C:\work\develop\scoop as the SCOOP environment variable and append C:\work\develop\scoop\shims to the PATH environment variable.

env

env

4.2 Download and Configure vcpkg, Then Install Dependency Libraries

The following installs the required dependency libraries, specifically: openssl and libsrtp. Other optional dependencies (e.g. ffmpeg) should also be installable, though they have not been tested yet.

For detailed vcpkg usage, refer to:

  1. Download vcpkg, which includes various configuration scripts and build scripts for open-source libraries. Assume the download path is C:\work\develop:

    1
    git clone https://github.com/microsoft/vcpkg
  2. Download the pre-built vcpkg package manager tool:

    1
    .\vcpkg\bootstrap-vcpkg.bat -disableMetrics
  3. Build openssl:

    1
    .\vcpkg\vcpkg.exe install --triplet=x64-windows-static openssl
  4. Build libsrtp (requires ENABLE_OPENSSL):

    Edit C:\work\develop\vcpkg\ports\libsrtp\portfile.cmake and update vcpkg_configure_cmake to the following: (Note: the configuration below has been updated to match the current version)

    1
    2
    3
    4
    5
    6
    7
    8
    vcpkg_cmake_configure(
    SOURCE_PATH "${SOURCE_PATH}"
    OPTIONS
    "-DCMAKE_PROJECT_INCLUDE=${CMAKE_CURRENT_LIST_DIR}/cmake-project-include.cmake"
    -DLIBSRTP_TEST_APPS=OFF
    -DENABLE_OPENSSL:BOOL=ON
    ${FEATURE_OPTIONS}
    )
    1. Then build (official method):

      1
      .\vcpkg\vcpkg.exe install --triplet=x64-windows-static libsrtp
    2. Or alternatively (the method I used later):

      1
      .\vcpkg\vcpkg.exe install "libsrtp[openssl]:x64-windows-static"

    Note: I successfully compiled the program using method 1, but later discovered a WebRTC issue. After investigation, it appeared to be a compatibility problem between OpenSSL and libsrtp. I had originally built libsrtp using the official method, and the issue was resolved only after rebuilding libsrtp with the command above.

    1
    2
    3
    # Uninstall first, then reinstall
    .\vcpkg\vcpkg.exe remove libsrtp:x64-windows-static --recurse
    .\vcpkg\vcpkg.exe install "libsrtp[openssl]:x64-windows-static"

5. Compile ZLMediaKit

Open the VS2022 developer command prompt from the Start Menu (x64 Native Tools Command Prompt for VS 2022). The PowerShell-based x64 version may not be available by default — you can start with the cmd version and then run powershell to switch to PowerShell.

tools

tools

5.1 Modify CMakeLists.txt

Search for OPENSSL_LIBRARIES in the file and replace the surrounding block with the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Check if openssl is installed
# find openssl installed
find_package(OpenSSL QUIET)
if(OPENSSL_FOUND AND ENABLE_OPENSSL)
message(STATUS "found library: ${OPENSSL_LIBRARIES}, ENABLE_OPENSSL defined")
include_directories(${OPENSSL_INCLUDE_DIR})
update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_OPENSSL)
update_cached_list(MK_LINK_LIBRARIES ${OPENSSL_LIBRARIES})
if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND OPENSSL_USE_STATIC_LIBS)
update_cached_list(MK_LINK_LIBRARIES ${CMAKE_DL_LIBS})
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
# On Windows, OpenSSL (especially vcpkg static libs) depends on CryptoAPI
update_cached_list(MK_LINK_LIBRARIES Crypt32)
# WS2_32 is already included in the WIN32 branch below, so this is optional
# update_cached_list(MK_LINK_LIBRARIES ws2_32)
endif()
else()
set(ENABLE_OPENSSL OFF)
set(ENABLE_WEBRTC OFF)
message(WARNING "openssl not found; rtmp will not support flash player, and https/wss/rtsps/rtmps/webrtc will be disabled")
endif()

The key change is to replace the block with the following snippet — leave the rest untouched (the exact location may vary between ZLMediaKit versions, so pay attention to where you apply the change):

1
2
3
4
5
6
7
8
if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND OPENSSL_USE_STATIC_LIBS)
update_cached_list(MK_LINK_LIBRARIES ${CMAKE_DL_LIBS})
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
# On Windows, OpenSSL (especially vcpkg static libs) depends on CryptoAPI
update_cached_list(MK_LINK_LIBRARIES Crypt32)
# WS2_32 is already included in the WIN32 branch below, so this is optional
# update_cached_list(MK_LINK_LIBRARIES ws2_32)
endif()

5.2 Run the Build Commands

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Run the following commands from the ZLMediaKit source root directory.
# Make sure you have downloaded the ZLMediaKit source and run: git submodule update --init --recursive
mkdir build
cd build

$VCPKG_CMAKE = 'C:\work\develop\vcpkg\scripts\buildsystems\vcpkg.cmake'
$VCPKG_INSTALL_PATH = 'C:\work\develop\vcpkg\installed\x64-windows-static'

$CMAKE_OPTIONS = @(
"-GCodeBlocks - Ninja"
"-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo"
"-DCMAKE_C_COMPILER:STRING=cl.exe"
"-DCMAKE_CXX_COMPILER:STRING=cl.exe"
"-DCMAKE_TOOLCHAIN_FILE:FILEPATH=$VCPKG_CMAKE"
"-DCMAKE_PREFIX_PATH:FILEPATH=$VCPKG_INSTALL_PATH"
"-DVCPKG_TARGET_TRIPLET:STRING=x86-windows-static"
"-DENABLE_WEBRTC:BOOL=ON"
)

cmake .. @CMAKE_OPTIONS
cmake --build . --target all

After a successful build, a release directory will appear in the source root containing the compiled binaries.
Release

6. Running

Navigate to C:\work\develop\ZLMediaKit\release\windows\RelWithDebInfo and double-click MediaServer.exe to run it directly.

Run

You only need to copy MediaServer.exe, MediaServer.pdb, and the www directory to another location to use the basic functionality.

Release

7. Troubleshooting

Issue 1: WebRTC Shows an OpenSSL Error

Cause: A compatibility issue between OpenSSL and libsrtp. libsrtp needs to be rebuilt.

1
2
3
# Uninstall first, then reinstall
.\vcpkg\vcpkg.exe remove libsrtp:x64-windows-static --recurse
.\vcpkg\vcpkg.exe install "libsrtp[openssl]:x64-windows-static"