[转] How To Compile OpenSSL for the iPhone

This is a quick tutorial to show you how to minimally compile a version of the openssl and crypto libraries for the iPhone/iPad.

Download and Configure OpenSSL

First thing to do is grab the openssl source.  You can get that here.  I’ll be using openssl-1.0.0 for this demo.  Unzip this file (mines on the desktop).  Open up a terminal and go to the unzipped folder and run the default configuration.  The argument passed is where your ‘make install’ will place the compiled libraries. You should replace this with your path.

cd Desktop/openssl-1.0.0
./config --openssldir=/Users/airpard/Desktop/openssl_ios/ no-asm

* Note if you want a simulator build you should do a regular make; make install at this point. The following steps are for armv6 and armv7 using the latest v4.2 iOS environment.

Edit the Makefile

Next thing to do is open up the make file.  This is named “Makefile” in the current directory you should already be in with the terminal.  Here are the list of changes to make (for armv7, replace armv6 references below):

Find CC= cc and change it to:
CC= /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2
 
Find -arch i386 in CFLAG and change it to:
-arch armv6
 
Find CFLAG and add to the BEGINNING!!:
-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk
 
Find SHARED_LDFLAGS=-arch i386 -dynamiclib and change it to:
SHARED_LDFLAGS=-arch armv6 -dynamiclib
 
Find PEX_LIBS= -Wl, -search_paths_firstxc and change it to:
PEX_LIBS= -Wl

Fix Build Error

If you build it at this point you may have noticed a build error. To fix this open up ui_openssl.c. This is located in openssl-1.0.0/crypto/ui/ folder. If you have a text editor with line numbers, head down to line 407. Otherwise do a text search to make this change:

static volatile sig_atomic_t intr_signal;
to
static volatile int intr_signal;

Save your changes and you should now be able to build with no errors.

Build Libraries

make
make install

That’s it. You’ll notice that everything was moved to the path provided in step 1 when configuring openssl. Remember to add the include folder to your Xcode project. Also, remember these libraries are only built for the iPhone and will not work in the simulator. You can change all the armv6 references to i386 and build it again if you choose to. Happy Coding!

 

找到build_all: build_libs build_apps build_tests build_tools(大概在242行)
修改为build_all: build_libs build_apps build_tools

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值