参考:https://github.com/Haivision/srt/blob/master/docs/build/build-win.md
一、精简步骤
1、准备cmake工具,并添加到系统环境变量中
https://cmake.org/download
2、准备vs2019社区版开发环境
3、克隆srt源码
git clone https://github.com/Haivision/srt.git
4、构建、编译多线程C++11标准库非加密的srt.dll
cd srt
mkdir build
cmake ../ -G"Visual Studio 16 2019" -A x64 -DENABLE_ENCRYPTION=OFF -DENABLE_STDCXX_SYNC=ON
cmake --build .
5、成品
二、详细步骤
Building SRT for Windows(编译Windows版本的SRT)
1. Prerequisites(开发环境)
1.1. Build Tool Dependencies(构建工具)
The following are the recommended prerequisites to build srt on Windows. 以下是在Windows上构建 srt 的前提。
- CMake v2.8.12 or higher (cross-platform family of tools to build software)
- git client (source code management tool)
- Visual Studio (compiler and linker)
1.2. External Library Dependencies(外部库的依赖关系)
1.2.1. Cryptographic Library(加密库)
SRT has an external dependency on cryptographic library.This dependency can be disabled by -DENABLE_ENCRYPTION=OFF CMake build option.With disabled encryption SRT will be unable to establish secure connections,only unencrypted mode can be used. SRT有一个外部依赖于加密库。 这个依赖可以通过-DENABLE_ENCRYPTION=OFF 的CMake构建选项来禁用。 禁用加密后,SRT将无法建立安全连接,只能使用未加密的模式。
With the enabled SRT encryption,one of the following Crypto libraries is required: 启用SRT加密后,需要以下加密库之一:
OpenSSL (default)LibreSSL MbedTLS
1.2.2. Threading Library(线程库)
SRT as of v1.4.2 supports two threading libraries: 从v1.4.2开始,SRT支持两个线程库:
- Standard C++ thread library available in C++11 (default on Windows)
pthreads (not recommended on Windows)
The pthreads library is provided out-of-the-box on all POSIX-based systems.On Windows it can be provided as a 3rd party library (see below).However the C++ standard thread library is recommended to be used on Windows. pthreads 库在所有基于posix的系统上都是开箱即用的。 在Windows上,它可以作为第三方库提供(见下文)。 但是,推荐在Windows上使用c++标准线程库。
1.3. Package Managers(软件包管理器)
1.3.1. VCpkg Packet Manager (optional) VCpkg包管理器(可选)
Can be used to:
- build OpenSSL library (dependency of SRT).
- build pthreads library (dependency of SRT).
vcpkg is a C++ library manager for Windows, Linux and MacOS. Consider its prerequisites before proceeding. vcpkg是一个c++库管理器,适用于Windows, Linux和MacOS。 在继续之前考虑它的先决条件。
The vcpkg library manager has preconfigured building procedures for OpenSSL and pthreads libraries. They can be easily built and further used as dependencies of SRT library. vcpkg库管理器已经为OpenSSL 和pthreads 库预先配置了构建过程。它们可以很容易地构建,并进一步用作SRT库的依赖项。
Note! vcpkg does not support LibreSSL or MbedTLS libraries.
Clone vcpkg using git, and build it.
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
The current working directory will further be referenced as VCPKG_ROOT .
set VCPKG_ROOT=%cd%
1.3.2. NuGet Manager (optional)
NuGet package manager can be used to get a prebuilt version of pthreads library for Windows.
Download nuget CLI to the desired folder.
The directory with NuGet will further be referenced as NUGET_ROOT .
set NUGET_ROOT=%cd%
2. Preparing Dependencies(准备依赖关系)
2.1 Cryptographic Library(加密库)
To build SRT with support for encryption,one of the following Crypto libraries is required:
OpenSSL (recommended)LibreSSL MbedTLS
2.1.1. Install OpenSSL
2.1.1.1. Using vcpkg
Note! The vcpkg working directory is referenced as VCPKG_ROOT .
Building openssl library using x64 toolset:
cd VCPKG_ROOT
vcpkg install openssl --triplet x64-windows
The next step is to integrate vcpkg with the build system, so that CMake can locate openssl library.
vcpkg integrate install
CMake will be able to find openssl given the following option is provided:
-DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%\\scripts\\buildsystems\\vcpkg.cmake
2.1.1.2. Using Installer (Windows)
The 64-bit OpenSSL package for Windows can be downloaded using the following link: Win64OpenSSL_Light-1_1_1c.
Note! The last letter or version number may change and older versions may become no longer available. In that case find the appropriate installer here: Win32OpenSSL.
Download and run the installer. The library is expected to be installed in C:\Program Files\OpenSSL-Win64 . Add this path to the user’s or system’s environment variable PATH .
It’s expected to be installed in C:\OpenSSL-Win64 . Note that this version is most likely compiled for Visual Studio 2013. For other versions please follow instructions in Section 2.1.1.3 Build from Sources.
2.1.1.3. Build from Sources
Download and compile the sources from the OpenSSL website. The instructions for compiling on Windows can be found here: link.
Note! ActivePerl and nasm are required to build OpenSSL.
2.1.2. Install MbedTLS
MbedTLS source code can be downloaded from the website.
MbedTLS comes with cmake build system support. Use the CMAKE_INSTALL_PREFIX variable to specify the directory that will contain the MbedTLS headers and libraries. Note that building MbedTLS as a DLL is broken in version 2.16.3. You have to link it statically.
2.1.3. Install LibreSSL
LibreSSL has header files that are compatible with OpenSSL, CMake can use it like OpenSSL with little configuration. The source code and binaries can be downloaded from here: link.
Since there are no recent Windows builds, the only option is to build a new version from sources. LibreSSL comes with CMake build system support. Use the CMAKE_INSTALL_PREFIX variable to specify the directory that will contain the LibreSSL headers and libraries.
2.2. Threading Library(线程库)
SRT can use one of these two threading libraries: SRT可以使用这两个线程库中的一个:
- C++11 threads (SRT v1.4.2 and above) - recommended, default since SRT v1.4.4;
pthreads (not recommended on Windows).
2.2.1. Using C++11 Threading(采用C++线程库)
To be able to use the standard C++ threading library (available since C++11) specify the CMake option -DENABLE_STDCXX_SYNC=ON . This way there will be also no external dependency on the threading library. Otherwise the external PThreads for Windows wrapper library is required. 为了能够使用标准的c++线程库(从c++ 11开始可用),指定CMake选项 -DENABLE_STDCXX_SYNC=ON 。 这样,线程库也不会有外部依赖。 否则,需要外部PThreads for Windows线程库。
2.2.2. Building PThreads
It is not recommended to use pthreads port on Windows. Consider using C++11 instead,
2.2.2.1. Using vcpkg
Note! The vcpkg working directory is referenced as VCPKG_ROOT .
Build the pthreads library using the x64 toolset:
vcpkg install pthreads --triplet x64-windows
The next step is to integrate vcpkg with the build system, so that CMake can locate pthreads library.
vcpkg integrate install
Now go to the srt-xtransmit cloned folder XTRANSMIT_ROOT and run cmake to generate build configuration files.
CMake will be able to find openssl given the following option is provided:
-DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%\\scripts\\buildsystems\\vcpkg.cmake
2.2.2.2. Using NuGet
This step assumes the NuGet is available from the NUGET_ROOT folder (refer to 1.3.2. NuGet Manager (optional)).
Run nuget to install pthreads to the specified path. In the example below the library will be installed in C:\pthread-win32 .
nuget install cinegy.pthreads-win64 -version 2.9.1.17 -OutputDirectory C:\pthread-win32
Two CMake options have to be provided on the step 3.2. Generate Build Files.
-DPTHREAD_INCLUDE_DIR="C:\pthread-win32\cinegy.pthreads-win64.2.9.1.17\sources"
-DPTHREAD_LIBRARY="C:\pthread-win32\cinegy.pthreads-win64.2.9.1.17\runtimes\win-x64\native\release\pthread_lib.lib"
2.2.2.3. Build pthreads4w from Sources
Download the source code from SourceForge (link) and follow the build instructions.
2.2.2.4. Build pthread-win32 from Sources
Compile and install pthread-win32 for Windows from GitHub: link.
- Using Visual Studio 2013, open the project file
pthread_lib.2013.vcxproj - Select configuration:
Release and x64 . - Make sure that the
pthread_lib project will be built. - After building, find the
pthread_lib.lib file (directory is usually bin\x64_MSVC2013.Release ). Copy this file to C:\pthread-win32\lib (or whatever other location you configured in variables). - Copy include files to
C:\pthread-win32\include (pthread.h , sched.h , and semaphore.h are in the toplevel directory. There are no meaningful subdirs here). Note that win## is part of the project name. It will become win32 or win64 depending on the selection.
3. Building SRT(编译SRT)
3.1. Cloning the Source Code(克隆源代码)
Retrieve the SRT source code from GitHub using a git client. 使用git客户端从GitHub获取SRT源代码。
git clone --branch <tag_name> https://github.com/haivision/srt.git srt
cd srt
set SRT_ROOT=%cd%
where --branch <tag_name> can be used to define a specific release version of SRT, e.g. --branch v1.4.1 .
Note! The current working directory will further be referenced as SRT_ROOT .
If --branch <tag_name> is omitted, the latest master is cloned. To get a specific release version run git checkout <tagname> from the SRT_ROOT folder.
git checkout v1.4.1
3.2. Generate Build Files(生成构建文件)
cmake ../ -G"Visual Studio 16 2019" -A x64
-DPTHREAD_INCLUDE_DIR="C:\pthread-win32\cinegy.pthreads-win64.2.9.1.17\sources"
-DPTHREAD_LIBRARY="C:\pthread-win32\cinegy.pthreads-win64.2.9.1.17\runtimes\win-x64\native\release\pthread_lib.lib"
Note! Additional options can be provided at this point.
In case vcpkg was used to build pthreads or OpenSSL, provide:
-DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%\\scripts\\buildsystems\\vcpkg.cmake
In case NuGet was used to get pre-built pthreads libray, provide:
-DPTHREAD_INCLUDE_DIR -DPTHREAD_LIBRARY
3.3. Build SRT(编译SRT)
cmake --build .
|