支持centos8.6、ubuntu20.04
export
建议开始之前,弄一台干净的机子,或者系统恢复到出厂设置,否则容易出问题
然后设置动态库默认加载目录(提高/usr/local/lib的优先级)
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
# ....其他自定义地址, export LD_LIBRARY_PATH=<path>:$LD_LIBRARY_PATH
为什么修改LD_LIBRARY_PATH呢?因为运行时动态库的搜索路径的先后顺序是:
- 编译目标代码时指定的动态库搜索路径,优先级最高,需要用户直接在
CMakeList.txt
里指定,例如:link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)- 环境变量
LD_LIBRARY_PATH
指定的动态库搜索路径,通过echo $LD_LIBRARY_PATH
来查看- 配置文件
/etc/ld.so.conf
中指定的动态库搜索路径,通过cat /etc/ld.so.conf
来查看- 系统默认动态库搜索路径
/lib、
/usr/lib、/usr/local/lib
这个顺序是compile gcc时写在程序内的,通常软件源代码自带的动态库不会太多,而我们的/lib
和/usr/lib
只有root权限才可以修改,而且配置文件/etc/ld.so.conf
也是root的事情,我们只好对LD_LIBRARY_PATH
进行操作。
现在,将export
添加到 /etc/profil
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
然后执行source使之生效
source /etc/profile
cmake/make/gcc/g++/gdb
首先进入管理者模式
#################################
# CentOS
#################################
sudo su
yum update
yum install git unzip zip
#################################
# Ubuntu
#################################
sudo su
apt update
apt install git unzip zip
准备好Linux设备,先安装cmake v3.20.2
#################################
# CentOS & Ubuntu
#################################
cd /usr/local
wget https://cmake.org/files/v3.20/cmake-3.20.2-linux-x86_64.tar.gz
tar zxvf cmake-3.20.2-linux-x86_64.tar.gz
mv cmake-3.20.2-linux-x86_64 /opt/cmake-3.20.2
ln -sf /opt/cmake-3.20.2/bin/* /usr/bin/
rm cmake-3.20.2-linux-x86_64.tar.gz
通过cmake
命令来验证
然后安装编译器和构建工具
make、
gcc、
g++、gdb
#################################
# CentOS
#################################
yum install make gcc g++ gdb -y
#################################
# Ubuntu
#################################
apt install make gcc g++ gdb -y
验证gdb版本
openssl
安装openssl,如果是ubuntu先要删除系统自带的版本
#################################
# Ubuntu
#################################
apt remove openssl
然后统一安装openssl
#################################
# CentOS & Ubuntu
#################################
cd /usr/local
# wget https://www.openssl.org/source/openssl-1.1.1i.tar.gz --no-check-certificate
wget https://cdn.datazhiqing.com/download/ffmpeg/openssl-1.1.1i.tar.gz --no-check-certificate
tar zxvf openssl-1.1.1i.tar.gz
mv openssl-1.1.1i openssl
cd openssl
./config shared
make -j 4
make install
通过openssl version
测试openssl版本信息
如果出现以下错误,就重启下机子
另外,cmake时需要指定openssl路径,否则cmake的find_package
可能找不到它,有两种方式:
- 通过
cmake
临时指定:
参考:cmake .. -DOPENSSL_ROOT_DIR=/usr/local/openssl -DOPENSSL_INCLUDE_DIR=/usr/local/include -DOPENSSL_CRYPTO_LIBRARY=/usr/local/lib/libcrypto.so -DOPENSSL_SSL_LIBRARY=/usr/local/lib/libssl.so
- 环境变量“一劳永逸”,执行的同时也写进
/etc/profile
中去
export OPENSSL_ROOT_DIR=/usr/local/openssl
export OPENSSL_INCLUDE_DIR=/usr/local/include/openssl
export OPENSSL_CRYPTO_LIBRARY=/usr/local/lib/libcrypto.so
export OPENSSL_SSL_LIBRARY=/usr/local/lib/libssl.so
ffmpeg
#创建依赖库下载目录
mkdir /usr/local/DOWNLOAD
#################################
# Ubuntu
#################################
sudo apt-get install libx11-dev xorg-dev libpulse-dev libasound2 libasound2-dev -y
yasm
#################################
# CentOS & Ubuntu
#################################
cd /usr/local/DOWNLOAD
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz --no-check-certificate
tar zxvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure
make -j 4
make install
fdk-aac
#################################
# CentOS & Ubuntu
#################################
cd /usr/local/DOWNLOAD
wget https://downloads.sourceforge.net/opencore-amr/fdk-aac-2.0.1.tar.gz --no-check-certificate
tar zxvf fdk-aac-2.0.1.tar.gz
cd fdk-aac-2.0.1
./configure --disable-static
make -j 4
make install
nasm
#################################
# CentOS & Ubuntu
#################################
cd /usr/local/DOWNLOAD
wget https://www.nasm.us/pub/nasm/releasebuilds/2.15/nasm-2.15.tar.gz --no-check-certificate
tar -vxf nasm-2.15.tar.gz
cd nasm-2.15
./configure
make -j 4
make install
sdl2
#################################
# CentOS & Ubuntu
#################################
cd /usr/local/DOWNLOAD
wget http://libsdl.org/release/SDL2-2.0.14.tar.gz --no-check-certificate
tar zxvf SDL2-2.0.14.tar.gz
cd SDL2-2.0.14
./configure
make -j 4
make install
curl
#################################
# CentOS & Ubuntu
#################################
cd /usr/local/DOWNLOAD
wget https://curl.haxx.se/download/curl-7.74.0.tar.gz --no-check-certificate
tar zxvf curl-7.74.0.tar.gz
cd curl-7.74.0
./configure --without-nss --with-ssl
make -j 4
make install
vpx
#################################
# CentOS & Ubuntu
#################################
cd /usr/local/DOWNLOAD
wget https://github.com/webmproject/libvpx/archive/v1.10.0/libvpx-1.10.0.tar.gz
unzip libvpx-v1.10.0.zip
cd libvpx-1.10.0
./configure --enable-pic --enable-static --enable-shared --as=yasm --target=generic-gnu
make -j 4
make install
opus
#################################
# CentOS & Ubuntu
#################################
cd /usr/local/DOWNLOAD
wget https://archive.mozilla.org/pub/opus/opus-1.3.tar.gz
tar xzvf opus-1.3.tar.gz
cd opus-1.3
./configure --enable-static --enable-shared
make -j 4
make install
x264
#################################
# CentOS & Ubuntu
#################################
cd /usr/local/DOWNLOAD
git clone https://code.videolan.org/videolan/x264.git
cd x264
./configure --enable-static --enable-shared --disable-opencl --disable-asm
make -j 4
make install
x265
#################################
# CentOS & Ubuntu
#################################
cd /usr/local/DOWNLOAD
wget http://ftp.videolan.org/pub/videolan/x265/x265_3.2.tar.gz --no-check-certificate
tar xzvf x265_3.2.tar.gz
cd x265_3.2/build/linux/
# !!! 这里需要手动
sh make-Makefiles.bash
# 按'c'再按'g'键保存退出
make -j 4
make install
ffmpeg
#查看链接依赖顺序
/sbin/ldconfig -v
#################################
# CentOS & Ubuntu
#################################
cd /usr/local
wget http://ffmpeg.org/releases/ffmpeg-4.3.2.tar.xz --no-check-certificate
tar -xvf ffmpeg-4.3.2.tar.xz
cd ffmpeg-4.3.2
PKG_CONFIG_PATH="/usr/local/lib/pkgconfig" ./configure --prefix=/usr/local \
--enable-static \
--enable-shared \
--enable-gpl \
--enable-libx264 \
--enable-libx265 \
--enable-libopus \
--enable-libvpx \
--enable-sdl2 \
--enable-zlib \
--enable-libfdk-aac \
--enable-openssl \
--enable-nonfree \
--extra-cflags=-Wno-implicit-function-declaration
make -j 4
make install
zlmediakit
手动Git下载ZLMediaKit
源码,版本v6.0
默认安装目录/usr/local/workspace/ZLMediaKit
,克隆代码,如果连不上多试几次
#################################
# CentOS & Ubuntu
#################################
mkdir -p /workspace
cd /workspace
#克隆代码,如果连不上多试几次
git clone -b 6.0 https://github.com/ZLMediaKit/ZLMediaKit.git
cd ZLMediaKit/
#克隆子模块
git submodule update --init
默认编译Debug,如果想要Release的,就需要修改CMakeList.txt
文件,将其中的这句话放开:
#set(CMAKE_BUILD_TYPE "Release")
编译ZLMediaKit
#################################
# CentOS & Ubuntu
#################################
cd /workspace/ZLMediaKit
mkdir build
cd build
#v6.0版本还没支持WebRTC
cmake ..
make -j4
make的时候要注意不能有错误
build文件夹里都是cmake编译过程中所构建的文件,而release文件里才是编译之后的可执行文件
测试结果:
cd ZLMediaKit/release/linux/Release
./MediaServer
CLion Remote编译
然后连接远程环境:
依然是上面的Linux环境,通过Clion远程remote编译,Remote CMake Project
后获取到大量运行工程,选择MediaServer
然后运行。