支持centos8.6、ubuntu20.04
export
建议开始之前,弄一台干净的机子,或者系统恢复到出厂设置,否则容易出问题
然后设置动态库默认加载目录(注意/usr/local/lib
不是系统默认的路径,/lib
和/usr/lib
才是)
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_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
这个顺序是compile gcc时写在程序内的,通常软件源代码自带的动态库不会太多,而我们的/lib
和/usr/lib
只有root权限才可以修改,而且配置文件/etc/ld.so.conf
也是root的事情,我们只好对LD_LIBRARY_PATH
进行操作。
sudo vi /etc/profile
添加几行内容(和刚才的export
一摸一样)
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
然后执行source使之生效
source /etc/profile
cmake/make/gcc/g++/gdb
首先进入管理者模式
sudo su
#centos
yum update
yum install git unzip zip
#ubuntu
apt update
apt install git unzip zip
准备好Linux设备,先安装cmake v3.20.2
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
#ubuntu
apt install make gcc g++ gdb
验证gdb版本
openssl
安装openssl,如果是ubuntu先要删除系统自带的版本
apt remove openssl
然后统一安装openssl
cd /usr/local
wget https://www.openssl.org/source/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
make install
测试openssl版本信息
openssl version
如果出现以下错误,就重启下机子
设置环境变量,否则cmake的find_package
找不到它,同时也写进/etc/profile
中去
参考: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
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
sudo apt-get install xorg-dev
#解决ffplay播放音频报错:Could not initialize SDL - Audio target 'pulse' not available,以及No such audio device问题
sudo apt-get install libpulse-dev
#以下这两个只安装libasound2也是可以的,如果不行就两个都安装
sudo apt-get install libasound2
sudo apt-get install libasound2-dev
yasm
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
sudo ./configure
sudo make
sudo make install
fdk-aac
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
make install
nasm
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
make install
sdl2
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
make install
curl
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
make install
vpx
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
make install
opus
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
make install
x264
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
make install
x265
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'再按'e'再按'g'键保存退出
make
make install
ffmpeg
#查看链接依赖顺序
/sbin/ldconfig -v
cd /usr/local/DOWNLOAD
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
./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 && make install
到此,就基本ok了,输入ffmpeg命令查看一下吧