当前位置: 首页 > 工具软件 > ZLMediaKit > 使用案例 >

交叉编译 ZLMediaKit

危裕
2023-12-01

交叉编译ZLMediaKit

x86 下编译 armv7

1. 安装toolchain 配置环境变量

下载编译器 环境gcc是5.9.4 所以找的比较底的版本确保兼容性

	mkdir /usr/local/arm-toolchain/ && cd /usr/local/arm-toolchain/
	wget https://releases.linaro.org/components/toolchain/binaries/4.9-2017.01/arm-linux-gnueabihf/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf.tar.xz 
	tar xvzf gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf.tar.xz
	vim /etc/profile 		// /etc/bash.bashrc
	
	// 添加到最后一行 export PATH=$PATH:/usr/local/arm-toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin
	source /etc/profile
	arm-linux-gnueabihf-gcc -v  // 显示如下编译器配置完成
	/*
	Using built-in specs.
	COLLECT_GCC=gcc
	COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
	OFFLOAD_TARGET_NAMES=nvptx-none:hsa
	OFFLOAD_TARGET_DEFAULT=1
	Target: x86_64-linux-gnu
	Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.4.0-1ubuntu1~20.04.1' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-Av3uEd/gcc-9-9.4.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
	Thread model: posix
	gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)

	*/

2. 编译依赖 (srtp2 openssl)

#### 2.1 openssl 编译

	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
	mkdir openssl-build && cd openssl-build
	../openssl-1.1.1f/config \
	no-asm shared \
	CROSS_COMPILE=/usr/local/arm-toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- \
	AR=ar \
	CC=gcc \
	CXX=g++ \
	RANLIB=ranlib \
	--prefix=/usr/local/openssl \
	--openssldir=/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.2 libsrtp 编译(如果不使用webrtc 可以忽略)

	wget https://codeload.github.com/cisco/libsrtp/tar.gz/refs/tags/v2.3.0 -O libsrtp-2.3.0.tar.gz
	tar -xvzf libsrtp-2.3.0.tar.gz
	cd libsrtp-2.3.0

	sudo cmake .. -DCMAKE_TOOLCHAIN_FILE=../armv7_hf.cmake -DENABLE_WEBRTC=true -DOPENSSL_ROOT=/usr/local/openssl -DOPENSSL_LIBRARIES=/usr/local/openssl/lib -DCMAKE_PREFIX_PATH="/usr/local/openssl

	sudo make -j8 && sudo make install 

3. 编译主程序

	git clone --depth 1 https://gitee.com/xia-chu/ZLMediaKit
	cd ZLMediaKit
	git submodule update --init
	mkdir build && cd build 
	cmake .. -DCMAKE_TOOLCHAIN_FILE=../armv7_hf.cmake -DENABLE_WEBRTC=true -DOPENSSL_ROOT=/usr/local/openssl -DOPENSSL_LIBRARIES=/usr/local/openssl/lib -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="/usr/local/openssl"
	cmake --build . --target MediaServer
	# 编译主程序在 ZLMediaKit/release 目录下

/* armv7hf.cmake
set(CMAKE_SYSTEM_NAME Linux)

set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_ANDROID_STL_TYPE gnustl_static)

set(TOOLCHAIN_PATH /usr/local/ARM-toolchain/gcc-linaro-5.5.0-2017.10-x86_64_arm-linux-gnueabi)

set(ANDROID_LIB_PATH ${TOOLCHAIN_PATH}/sysroot/usr/lib)

set(CMAKE_C_COMPILER ${TOOLCHAIN_PATH}/bin/arm-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PATH}/bin/arm-linux-gnueabi-g++)

*/

 类似资料: