ZLMediaKit 编译(Centos 7.9 环境)
1. 安装前说明
如果你是位新手,强烈建议使用 ubuntu16 或更新版本编译 ZLMediaKit,macOS 是次选推荐平台,最不推荐的是 centos6.*或 windows 平台。
编译之前需要安装下载git
yum update
yum install git
git version
运行结果如下:我的已经安装完成。
[root@hcss-ecs-cf3a ZLMediaKit]# yum update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* rpmfusion-free-updates: mirrors.ustc.edu.cn
No packages marked for update
[root@hcss-ecs-cf3a ZLMediaKit]#
[root@hcss-ecs-cf3a ZLMediaKit]#
[root@hcss-ecs-cf3a ZLMediaKit]#
[root@hcss-ecs-cf3a ZLMediaKit]# yum install git
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* rpmfusion-free-updates: mirrors.ustc.edu.cn
Package git-1.8.3.1-25.el7_9.x86_64 already installed and latest version
Nothing to do
[root@hcss-ecs-cf3a ZLMediaKit]# git version
git version 1.8.3.1
[root@hcss-ecs-cf3a ZLMediaKit]#
2. 编译器要求
ZLMediaKit 采用了 C++11 的语法和库,要求编译器支持完整的 C++11 标准,亦即:
- linux 上要求 gcc 版本 >= 4.8(4.7 应该也能支持)
- macOS 上 clang >= ???(我也不知道,估计大部分不会遇到这个问题)
- windows 上 visual stuido >= 2015(vs2013 某些版本也能编译通过,如果怕麻烦建议直接 vs2017)
2.1 gcc
如果你是 centos7 或以上用户,你可以这样安装 gcc 编译器:
sudo yum -y install gcc
sudo yum -y install gcc-c++
安装完成,查看版本号
[root@hcss-ecs-cf3a ZLMediaKit]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root@hcss-ecs-cf3a ZLMediaKit]#
[root@hcss-ecs-cf3a ZLMediaKit]# g++ --version
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2.2 cmake
先不要通过
yum install cmake安装cmake,版本太低,不满足要求
ZLMediaKit 采用 cmake 来构建项目,通过 cmake 才能生成 Makefile(或 Xcode/VS 工程),所以必须先安装 cmake 才能完成后续步骤。
centos7.9通过yum install cmake安装的版本是cmake version 2.8.12.2,直接运行则会报错,所以需要升级cmake的版本号
[root@uver138-test build]# cmake --version
cmake version 2.8.12.2
[root@uver138-test build]#
[root@uver138-test build]# cmake ..
CMake Error at CMakeLists.txt:2 (cmake_minimum_required):
CMake 3.1.3 or higher is required. You are running version 2.8.12.2
-- Configuring incomplete, errors occurred!
See also "/mnt/ZLMediaKit/build/CMakeFiles/CMakeOutput.log".
升级
#cmake安装需要openssl,所以首先安装
yum install openssl-devel
wget https://cmake.org/files/v3.26/cmake-3.26.3.tar.gz
tar zxvf cmake-3.26.3.tar.gz
cd cmake-3.26.3
./bootstrap
gmake
gmake install
如果cmake --version出现错误,参见blog.csdn.net/bacawa/arti…解决办法
[root@localhost cmake-3.26.3]# cmake -version
CMake Error: Could not find CMAKE_ROOT !!!
CMake has most likely not been installed correctly.
Modules directory not found in
/usr/local/bin
段错误(吐核)
原因:cmake 命令本来存在,然后进行了安装。 类似于缓存导致失败的一样。
hash -r
然后再执行
[root@localhost cmake-3.26.3]# cmake --version
cmake version 3.26.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).
版本已经升级了。
2.3 ffmpeg
直接安装可能会提示 没有可用软件包的错误,这里就要更新下yum源,按照以下步骤进行操作。
yum install SDL-devel
#安装 epel-release
yum install epel-release -y
#通过rpmfusion存储库安装 rpm
yum localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm
#清理缓存
yum clean all
#重新生成缓存
yum makecache
#升级yum源
yum uptade
#安装依赖 ffmpeg-devel
yum install ffmpeg-devel
#安装依赖ffmpeg
yum install ffmpeg
2.4 webrtc相关依赖库
参见官方 webrtc 编译与使用 文档即可
2.4.1 openssl 安装 (openssl 版本要求 1.1 以上)
wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz
tar -xvzf openssl-1.1.1k.tar.gz
yum install -y zlib zlib-devel perl-CPAN
./config shared --openssldir=/usr/local/openssl --prefix=/usr/local/openssl
make && make install
echo "/usr/local/lib64/" >> /etc/ld.so.conf
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
ldconfig
ln -s /usr/local/openssl/bin/openssl /usr/local/bin/openssl # 替换系统openssl,非必须
openssl version -a
2.4.2 libsrtp 安装
wget https://github.com/cisco/libsrtp/archive/refs/tags/v2.3.0.tar.gz
tar -xvzf libsrtp-2.3.0.tar.gz
cd libsrtp-2.3.0
./configure --enable-openssl --with-openssl-dir=/usr/local/openssl
make -j8 && make install
对于一些比较新的编译环境(如 GCC 10+),编译 libsrtp-2.3.0 可能会存在问题,可以考虑切换到 2.5.0 版本,即
wget https://github.com/cisco/libsrtp/archive/refs/tags/v2.5.0.tar.gz
tar -xvzf libsrtp-2.5.0.tar.gz
cd libsrtp-2.5.0
3. 下载源码
#国内用户推荐从同步镜像网站gitee下载
git clone --depth 1 https://gitee.com/xia-chu/ZLMediaKit
cd ZLMediaKit
#千万不要忘记执行这句命令
git submodule update --init
4. 编译源码
mkdir build
cd build
cmake .. -DENABLE_WEBRTC=true -DOPENSSL_ROOT_DIR=/usr/local/openssl -DOPENSSL_LIBRARIES=/usr/local/openssl/lib
cmake --build . --target MediaServer
# 最终输出
[ 96%] Built target test_rtcp_fci
[ 96%] Building CXX object tests/CMakeFiles/test_rtp.dir/test_rtp.cpp.o
[ 97%] Linking CXX executable ../../release/linux/Debug/test_rtp
[ 97%] Built target test_rtp
[ 97%] Building CXX object tests/CMakeFiles/test_wsServer.dir/test_wsServer.cpp.o
[ 97%] Linking CXX executable ../../release/linux/Debug/test_wsServer
[ 97%] Built target test_wsServer
[ 97%] Building CXX object tests/CMakeFiles/test_server.dir/test_server.cpp.o
[ 97%] Linking CXX executable ../../release/linux/Debug/test_server
[ 97%] Built target test_server
[ 98%] Built target jsoncpp
[ 98%] Linking CXX executable ../../release/linux/Debug/MediaServer
[100%] Built target MediaServer