最后更新于2022年8月10日 13:40:41
其实程序本身编译很简单的,难在下载下来跟自己的环境适配的过程,需要用到WebRTC拉流,编译过程记录如下:
原生的Ubuntu20.04-2:ubuntu 5.15.0-43-generic + gcc 9.4.0(其实5.4.0就够用了)
这里就算有openssl也推荐手动搞一下,不行就新旧版本并存嘛,因为openssl-libsrtp2-zlmediakit这一套有联动的,我怕路径不对,受影响,就从头搞一下。
# 从github wiki上面抄来的
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 # 这一步我就不执行了,之前电脑上装的有,而且我是ubuntu。
./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 # 我这里是写了个openssl.conf文件放在/etc/ld.so.conf.d文件夹下面了,一个道理。
ldconfig
ln -s /usr/local/openssl/bin/openssl /usr/local/bin/openssl # 这步我不做了,不想替换旧版本。
openssl version -a
这个一般人都没装,注意不要偷懒去apt安装libsrtp,否则会报错:
srtp_create() failed: unspecified failure (srtp_err_status_fail);
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
这样编译完是没有动态库的,手动添加:
make shared_library
cp libsrtp2.so libsrtp2.so.1 /usr/lib/x86_64-linux-gnu
这一步有点小问题,我的编译环境是ubuntu20,但是我的部署环境是16,部署环境里面/usr/lib/x86_64-linux-gnu/libstdc++.so.6的版本太低,所以这步我要多加一步静态编译libstdc++库,在zlmediakit根目录的CMakeList文件中添加静态编译如下:
# 解决version `GLIBCXX_3.4.26' not found问题
set(CMAKE_EXE_LINKER_FLAGS " -static-libstdc++")
然后正常编译即可:
mkdir build
cd build
cmake .. -DENABLE_WEBRTC=true -DOPENSSL_ROOT_DIR=/usr/local/openssl -DOPENSSL_LIBRARIES=/usr/local/openssl/lib
cmake --build . --target MediaServer