[webrtc 入门系列] libsrtp编译
libsrtp依赖openssl, 如果系统自带的openssl版本比较低, 可以使用源码编译高版本。
--enable-openssl
libsrtp
下载源码
tar -zxvf libsrtp-2.3.0.tar.gz
cd libsrtp-2.3.0/
sh build.sh
编译脚本
build.sh
cur_dir=$(cd "$(dirname "$0")"; pwd)
parent_dir=$(dirname $(pwd))
main_dir=$(dirname ${parent_dir})
echo "cur_dir = ${cur_dir}"
echo "parent_dir = ${parent_dir}"
echo "main_dir = ${main_dir}"
/bin/rm -rf build
/bin/rm -rf CMakeCache.txt
/bin/rm -rf cmake_install.cmake
#if [ $CROSS_COMPILE_CPU ];then
# ./configure "CFLAGS=${CMAKE_C_FLAGS}" --prefix=${cur_dir}/release --enable-openssl --with-openssl-dir=${main_dir}/release
#else
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=${main_dir}/release \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_OPENSSL=ON \
-DBUILD_SHARED_LIBS=OFF \
-DOPENSSL_ROOT_DIR=${main_dir}/release/lib \
-DOPENSSL_INCLUDE_DIR=${main_dir}/release/include \
..
#fi
make
make install
不使用cmake的话,用下面的方式编译
./configure --prefix=/home/webrtc/libsrtp-2.3.0/release --enable-openssl --with-openssl-dir=/home/webrtc/thirdparty/lib/openssl
make -j8
make install
静态链接zlib
find_package(ZLIB REQUIRED)
if(ZLIB_FOUND)
message(STATUS "Zlib Found!")
include_directories(${ZLIB_INCLUDE_DIR})
endif()
target_link_libraries(target_program ${ZLIB_LIBRARIES})
openssl
动态链接 openssl
使用系统自带的openssl动态库
find_package(OpenSSL REQUIRED)
if(OPENSSL_FOUND)
include_directories(${OPENSSL_INCLUDE_DIRS})
message(STATUS "OpenSSL Found!")
endif()
target_link_libraries(target_program ${CURL_LIBRARIES})
target_link_libraries(target_program OpenSSL::Crypto OpenSSL::SSL)
如果不想使用系统自带的openssl ,可以指定版本的openssl路径
给cmake添加下列变量:
-DOPENSSL_INCLUDE_DIR:指向 openssl的 include 目录
-DOPENSSL_SSL_LIBRARIES:指向 openssl的 lib 目录中的 libssl.so
-DOPENSSL_CRYPTO_LIBRARIES:指向 openssl的 lib 目录中的 libcrypto.so
// add_definitions(-DOPENSSL_INCLUDE_DIR)
静态链接openssl
添加以下的变量定义
set(OPENSSL_ROOT_DIR /home/public/openssl)
set(OPENSSL_USE_STATIC_LIBS TRUE)
源码编译openssl
cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.1.1i.tar.gz
tar -zxvf openssl-1.1.1i.tar.gz -C /usr/local/src
cd /usr/local/src/openssl-1.1.1i
./config shared zlib --openssldir=/usr/local/openssl --prefix=/usr/local/openssl
make -j8 && make install
把库路径环境添加到变量
临时测试
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/openssl/lib/
添加到/etc/ld.so.conf
echo "/usr/local/lib64/" >> /etc/ld.so.conf
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
然后 ldconfig
或者在文件/etc/profile最后面加上:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/openssl/lib/
然后 source /etc/profile
备份旧的
mv /usr/lib64/libssl.so /usr/lib64/libssl.so.old
mv /usr/lib64/openssl /usr/lib64/openssl.old
mv /usr/bin/openssl /usr/bin/openssl.old
建立软连接
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/lib/libssl.so /usr/local/lib64/libssl.so
ln -s /usr/local/openssl/lib/libcrypto.so /usr/local/lib64/libcrypto.so