ios之编译openssl成静态库
2014-06-18 16:10
471 查看
编译openssl,刚好在github上找到编译 i386
x86_64 armv7 armv7s arm64 这些的脚本,如下:
这里面可设置ios
sdk的版本及编译的指令集版本,把下载好的资源包和该文件放在一块执行该文件就可以了,不过如果你的xcode是4.5及以后的就不能编译armv6了,因为苹果在xcode4.5的时候就停止对armv6编译支持了,因为armv6在iphone3GS及以前用的cpu架构才是armv6的(详情:http://www.dnetzj.com/Content/437.html)。
如果通过该文件强制编译armv6就会出现错误:
ld: file is universal (5 slices) but does not contain a(n) armv6 slice: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/lib/darwin/libclang_rt.ios.a
file '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/lib/darwin/libclang_rt.ios.a' for architecture armv6
去xcode里查看libclang_rt.ios.a这个文件还的确只支持 i386
x86_64 armv7 armv7s arm64 。
那么要是想编译armv6怎么办呢,只能通过支持armv6的libclang_rt.ios.a这个文件的xcode,例如xcode4.4.1。下载xcode4.4.1命名为Xcode4.4.1或者把里面的libclang_rt.ios.a文件替换掉高版本的xcode里,这样比较乱还不如保留两个xcode版本,以待日后有用。
用xcode4.4.1的时候可以通过上面的文件执行,不过要该许多路径问题,还有一个办法是(其实上面的文件也是这个方法的合并):
a. 打开crypto/ui/ui_openssl.c进行编辑。
将
static volatile sig_atomic_t intr_signal;
修改为:
static volatile int intr_signal;
否则会出现一个编译错误。
b.执行目录下的congfigure:
./configure BSD-generic32 --openssldir=/Users/<username>/openssl-1.0.0g/openssl_armv6 如果不指定--openssldir的话就会吧静态库生成在openssl目录下
c.编辑 makefile 文件,找到:
CC= gcc
修改为:
CC= /Applications/Xcode4.4.1.app/Contents/Developer/usr/bin/gcc -arch armv6
下一行,在CFLAG = 的后面增加
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk
进行编译:
make
完成后就会在openssl目录下找到libcrypto.a和ibssl.a文件把之前编译好的i386
x86_64 armv7 armv7s arm64fat文件 合并在一起就行了,合并用lipo –create 命令
x86_64 armv7 armv7s arm64 这些的脚本,如下:
#!/bin/sh # Automatic build script for libssl and libcrypto # for iPhoneOS and iPhoneSimulator # # Created by Felix Schulze on 16.12.10. # Copyright 2010 Felix Schulze. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ########################################################################### # Change values here # # VERSION="1.0.1g" # SDKVERSION="7.1" # # # ########################################################################### # # # Don't change anything under this line! # # # ########################################################################### CURRENTPATH=`pwd` ARCHS="i386 x86_64 armv7 armv7s arm64" 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 case $DEVELOPER in *\ * ) echo "Your Xcode path contains whitespaces, which is not supported." exit 1 ;; esac case $CURRENTPATH in *\ * ) echo "Your path contains whitespaces, which is not supported by 'make install'." exit 1 ;; esac 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" fi mkdir -p "${CURRENTPATH}/src" mkdir -p "${CURRENTPATH}/bin" mkdir -p "${CURRENTPATH}/lib" tar zxf openssl-${VERSION}.tar.gz -C "${CURRENTPATH}/src" cd "${CURRENTPATH}/src/openssl-${VERSION}" for ARCH in ${ARCHS} do if [[ "${ARCH}" == "i386" || "${ARCH}" == "x86_64" ]]; 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}" mkdir -p "${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" LOG="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/build-openssl-${VERSION}.log" set +e if [[ "$VERSION" =~ 1.0.0. ]]; then ./Configure BSD-generic32 --openssldir="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" > "${LOG}" 2>&1 elif [ "${ARCH}" == "x86_64" ]; then ./Configure darwin64-x86_64-cc --openssldir="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" > "${LOG}" 2>&1 else ./Configure iphoneos-cross --openssldir="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" > "${LOG}" 2>&1 fi if [ $? != 0 ]; then echo "Problem while configure - Please check ${LOG}" exit 1 fi # add -isysroot to CC= sed -ie "s!^CFLAG=!CFLAG=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -miphoneos-version-min=7.0 !" "Makefile" make >> "${LOG}" 2>&1 if [ $? != 0 ]; then echo "Problem while make - Please check ${LOG}" exit 1 fi set -e make install >> "${LOG}" 2>&1 make clean >> "${LOG}" 2>&1 done echo "Build library..." lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/lib/libssl.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/lib/libssl.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/lib/libssl.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/lib/libssl.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/lib/libssl.a -output ${CURRENTPATH}/lib/libssl.a lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/lib/libcrypto.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/lib/libcrypto.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/lib/libcrypto.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/lib/libcrypto.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/lib/libcrypto.a -output ${CURRENTPATH}/lib/libcrypto.a mkdir -p ${CURRENTPATH}/include cp -R ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/include/openssl ${CURRENTPATH}/include/ echo "Building done." echo "Cleaning up..." rm -rf ${CURRENTPATH}/src/openssl-${VERSION} echo "Done."
这里面可设置ios
sdk的版本及编译的指令集版本,把下载好的资源包和该文件放在一块执行该文件就可以了,不过如果你的xcode是4.5及以后的就不能编译armv6了,因为苹果在xcode4.5的时候就停止对armv6编译支持了,因为armv6在iphone3GS及以前用的cpu架构才是armv6的(详情:http://www.dnetzj.com/Content/437.html)。
如果通过该文件强制编译armv6就会出现错误:
ld: file is universal (5 slices) but does not contain a(n) armv6 slice: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/lib/darwin/libclang_rt.ios.a
file '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/lib/darwin/libclang_rt.ios.a' for architecture armv6
去xcode里查看libclang_rt.ios.a这个文件还的确只支持 i386
x86_64 armv7 armv7s arm64 。
那么要是想编译armv6怎么办呢,只能通过支持armv6的libclang_rt.ios.a这个文件的xcode,例如xcode4.4.1。下载xcode4.4.1命名为Xcode4.4.1或者把里面的libclang_rt.ios.a文件替换掉高版本的xcode里,这样比较乱还不如保留两个xcode版本,以待日后有用。
用xcode4.4.1的时候可以通过上面的文件执行,不过要该许多路径问题,还有一个办法是(其实上面的文件也是这个方法的合并):
a. 打开crypto/ui/ui_openssl.c进行编辑。
将
static volatile sig_atomic_t intr_signal;
修改为:
static volatile int intr_signal;
否则会出现一个编译错误。
b.执行目录下的congfigure:
./configure BSD-generic32 --openssldir=/Users/<username>/openssl-1.0.0g/openssl_armv6 如果不指定--openssldir的话就会吧静态库生成在openssl目录下
c.编辑 makefile 文件,找到:
CC= gcc
修改为:
CC= /Applications/Xcode4.4.1.app/Contents/Developer/usr/bin/gcc -arch armv6
下一行,在CFLAG = 的后面增加
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk
进行编译:
make
完成后就会在openssl目录下找到libcrypto.a和ibssl.a文件把之前编译好的i386
x86_64 armv7 armv7s arm64fat文件 合并在一起就行了,合并用lipo –create 命令
相关文章推荐
- Xcode环境下osip,eXosip, openssl的静态库编译方法(编译出来给IOS使用)
- Xcode环境下osip,eXosip, openssl的静态库编译方法(编译出来给IOS使用)
- 编译OpenSSL 动态库/静态库以及运行时库的选择
- Android下编译OpenSSL静态库
- iOS静态库的编译
- 在iOS上使用Clucene——编译静态库
- 在iOS上使用Clucene——编译静态库
- 编译OpenSSL 动态库/静态库以及运行时库的选择
- Android下编译OpenSSL静态库
- mac电脑上编译能在ios上用的 ffmpeg 静态库 (成功经验)有疑问可以留言
- 编译ios版openssl(2013/01/28)
- iOS开发之---静态库的编译以及相关问题的处理
- 在Android下编译openssl静态库(平台:Windows)
- ios 编译静态库
- IOS开发之---静态库的编译以及相关问题的处理
- iOS开发之---静态库的编译以及相关问题的处理
- openssl在ios下的编译
- IOS开发之---静态库的编译以及相关问题的处理
- iOS开发之---静态库的编译以及相关问题的处理
- iOS静态库的编译