编译ios版本的librtmp+openssl
http://blog.csdn.net/cjj198561/article/details/28955461
编译librtmp需要先编译openssl,因为librtmp依赖openssl
首先编译openssl:
把以下内容保存为shell脚本:
#!/bin/sh
VERSION="1.0.1h" #指明openssl的版本信息,比如下载的是openssl-1.0.1h.tar.gz那么对于就填写1.0.1h
SDKVERSION="7.1" #指明ios sdk的版本号,目前最新的是7.1,不清楚的同学可以 ls /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/ 一下看看自己的iPhoneOS7.1.sdk是不是7.1
CURRENTPATH=`pwd`
ARCHS="i386 armv7 armv7s arm64"
BUILDPATH="${CURRENTPATH}/build"
LIBPATH="${CURRENTPATH}/lib"
INCLUDEPATH="${CURRENTPATH}/include"
SRCPATH="${CURRENTPATH}/src"
LIBSSL="libssl.a"
LIBCRYPTO="libcrypto.a"
DEVELOPER=`xcode-select -print-path`
if [ ! -d "$DEVELOPER" ]; then
echo "xcode path is not set correctly $DEVELOPER does not exist (most likely because of xcode > 4.3)"
echo "run"
echo "sudo xcode-select -switch <xcode path>"
echo "for default installation:"
echo "sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer"
exit 1
fi
set -e
if [ ! -e openssl-${VERSION}.tar.gz ]; then
echo "Downloading openssl-${VERSION}.tar.gz"
curl -O http://www.openssl.org/source/openssl-${VERSION}.tar.gz
else
echo "Using openssl-${VERSION}.tar.gz"
# Remove the source directory if already exist
rm -rf "${SRCPATH}/openssl-${VERSION}"
fi
mkdir -p "${SRCPATH}"
mkdir -p "${BUILDPATH}"
mkdir -p "${LIBPATH}"
mkdir -p "${INCLUDEPATH}"
tar zxf openssl-${VERSION}.tar.gz -C "${SRCPATH}"
cd "${SRCPATH}/openssl-${VERSION}"
LIBSSL_REPO=""
LIBCRYPTO_REPO=""
for ARCH in ${ARCHS}
do
if [ "${ARCH}" == "i386" ];
then
PLATFORM="iPhoneSimulator"
else
sed -ie "s!static volatile sig_atomic_t intr_signal;!static volatile intr_signal;!" "crypto/ui/ui_openssl.c"
PLATFORM="iPhoneOS"
fi
export CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
export CROSS_SDK="${PLATFORM}${SDKVERSION}.sdk"
export BUILD_TOOLS="${DEVELOPER}"
echo "Building openssl-${VERSION} for ${PLATFORM} ${SDKVERSION} ${ARCH}"
echo "Please stand by..."
export CC="${BUILD_TOOLS}/usr/bin/gcc -arch ${ARCH}"
OUTPATH="${BUILDPATH}/openssl-${PLATFORM}${SDKVERSION}-${ARCH}.sdk"
mkdir -p "${OUTPATH}"
LOG="${OUTPATH}/build-openssl-${VERSION}.log"
if [[ "$VERSION" =~ 1.0.0. ]]; then
./Configure BSD-generic32 --openssldir="${OUTPATH}" > "${LOG}" 2>&1
else
./Configure iphoneos-cross --openssldir="${OUTPATH}" > "${LOG}" 2>&1
fi
# add -isysroot to CC=
sed -ie "s!^CFLAG=!CFLAG=-isysroot ${CROSS_TOP}/Platforms/${PLATFORM}.platform/Developer/SDKs/${CROSS_SDK} -miphoneos-version-min=7.0 !" "Makefile"
make >> "${LOG}" 2>&1
make install >> "${LOG}" 2>&1
make clean >> "${LOG}" 2>&1
LIBSSL_REPO+="${OUTPATH}/lib/${LIBSSL} "
LIBCRYPTO_REPO+="${OUTPATH}/lib/${LIBCRYPTO} "
done
echo "Build library..."
lipo -create ${LIBSSL_REPO}-output ${LIBPATH}/${LIBSSL}
lipo -create ${LIBCRYPTO_REPO}-output ${LIBPATH}/${LIBCRYPTO}
cp -R ${BUILDPATH}/openssl-iPhoneSimulator${SDKVERSION}-i386.sdk/include/openssl ${INCLUDEPATH}/
echo "Building done."
echo "Cleaning up..."
rm -rf ${SRCPATH}/openssl-${VERSION}
echo "Done."
保存脚本,添加脚本的执行权限(chmod +x 脚本名称)
运行脚本
不出意外是可以编译成功的,如果失败,可以以打开那个log文件,查看失败原因。
编译成功以后,把lib文件和include拷贝到你的librtmp目录(可以新建一个空得librtmp目录),在librtmp目录里面同样写一个shell脚本,脚本如下:
#!/bin/sh
SDKVERSION="7.1" #这里跟openssl的地方是一个意思
CURRENTPATH=`pwd`
ARCHS="i386 armv7 armv7s arm64"
LIBPATH="${CURRENTPATH}/lib" #这里就是刚才拷贝过来的目录,不要修改,因为librtmp最后生成的也放到了这个下面
INCLUDEPATH="${CURRENTPATH}/include" #这里就是刚才拷贝过来的目录,不要修改,因为librtmp最后生成的也放到了这个下面
LIBRTMPREPO="git://git.ffmpeg.org/rtmpdump"
BUILDPATH="${CURRENTPATH}/build"
SRCPATH="${CURRENTPATH}/src"
LIBRTMP="librtmp.a"
DEVELOPER=`xcode-select -print-path`
if [ ! -d "$DEVELOPER" ]; then
echo "xcode path is not set correctly $DEVELOPER does not exist (most likely because of xcode > 4.3)"
echo "run"
echo "sudo xcode-select -switch <xcode path>"
echo "for default installation:"
echo "sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer"
exit 1
fi
# Check whether openssl has already installed on the machine or not.
# libcrypt.a / libssl.a
set -e
echo ‘Check openssl installation‘
if [ -f "${LIBPATH}/libcrypto.a" ] && [ -f "${LIBPATH}/libssl.a" ] && [ -d "${INCLUDEPATH}/openssl" ]; then
echo ‘Openssl for iOS has already installed, no need to install openssl‘
else
echo ‘Openssl for iOS not found, will install openssl for iOS‘
./build-libssl.sh
echo ‘Succeeded to install openssl‘
fi
# Download librtmp source code from git repository
# We assuem the user already installed git client.
echo ‘Clone librtmp git repository‘
# Remove the directory if already exist
rm -rf "${SRCPATH}/rtmpdump"
git clone ${LIBRTMPREPO} src/rtmpdump
cd "${SRCPATH}/rtmpdump/librtmp"
LIBRTMP_REPO=""
for ARCH in ${ARCHS}
do
if [ "${ARCH}" == "i386" ];
then
PLATFORM="iPhoneSimulator"
else
PLATFORM="iPhoneOS"
fi
export CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
export CROSS_SDK="${PLATFORM}${SDKVERSION}.sdk"
export BUILD_TOOLS="${DEVELOPER}"
echo "Building librtmp for ${PLATFORM} ${SDKVERSION} ${ARCH}"
echo "Please wait..."
# add arch to CC=
sed -ie "s!AR=\$(CROSS_COMPILE)ar!AR=/usr/bin/ar!" "Makefile"
sed -ie "/CC=\$(CROSS_COMPILE)gcc/d" "Makefile"
echo "CC=\$(CROSS_COMPILE)gcc -arch ${ARCH}" >> "Makefile"
export CROSS_COMPILE="${DEVELOPER}/usr/bin/"
export XCFLAGS="-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -miphoneos-version-min=7.0 -I${INCLUDEPATH} -arch ${ARCH}"
if [ "${ARCH}" == "i386" ];
then
export XLDFLAGS="-L${LIBPATH} -arch ${ARCH}"
else
export XLDFLAGS="-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -miphoneos-version-min=7.0 -L${LIBPATH} -arch ${ARCH}"
fi
OUTPATH="${BUILDPATH}/librtmp-${PLATFORM}${SDKVERSION}-${ARCH}.sdk"
mkdir -p "${OUTPATH}"
LOG="${OUTPATH}/build-librtmp.log"
make SYS=darwin >> "${LOG}" 2>&1
make SYS=darwin prefix="${OUTPATH}" install >> "${LOG}" 2>&1
make clean >> "${LOG}" 2>&1
LIBRTMP_REPO+="${OUTPATH}/lib/${LIBRTMP} "
done
echo "Build universal library..."
lipo -create ${LIBRTMP_REPO}-output ${LIBPATH}/${LIBRTMP}
mkdir -p ${INCLUDEPATH}
cp -R ${BUILDPATH}/librtmp-iPhoneSimulator${SDKVERSION}-i386.sdk/include/ ${INCLUDEPATH}/
echo "Building done."
echo "Cleaning up..."
rm -rf ${SRCPATH}/rtmpdump
echo "Done."
保存脚本
运行脚本
不出意外就编译成功了。
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。