在你的 iOS App中 使用 OpenSSL 库

来源:互联网 发布:51单片机蜂鸣器电路图 编辑:程序博客网 时间:2024/06/08 17:03

原文地址:http://www.x2on.de/2010/07/13/tutorial-iphone-app-with-compiled-openssl-1-0-0a-library/ ,本文有少许地方做了调整。

1、下载OpenSSL源代码库:

http://www.openssl.org/source/

当前最新版本1.0.0d。

下载后,将其中的 openssl-1.0.0x 目录解压出来放在合适的地方。

2、编译OpenSSL

openssl是一个c语言函数库,为方便在Xcode中使用,我们需要把它编译为静态库。

打开crypto/ui/ui_openssl.c进行编辑。

static volatile sig_atomic_t intr_signal;

 

修改为:

static volatile int intr_signal;

 

否则会出现一个编译错误。

2.1 编译 i386 库(用于iPhone模拟器)

执行以下命令:

mkdir ssllibs

 

将在用户主目录下建立ssllibs目录。

切换到openssl-1.0.0a安装(解压)目录,在其下建立3个子目录:

cd openssl-1.0.0a

mkdir openssl_armv6 openssl_armv7 openssl_i386

 

执行目录下的congfigure:

./configure BSD-generic32 --openssldir=/Users/<username>/openssl-1.0.0a/openssl_i386

 

编辑 makefile 文件,找到:

CC= gcc

修改为:

CC= /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -arch i386

 

下一行,在CFLAG = 的后面增加

-isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk

 

进行编译:

make

make install

执行到make时,报错:

make[1]: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc: No such file or directory

实际上我查了在 /应用程序/xcode/developer/...下面是有设个gcc的

解决:要加上全路径, /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc


注意:

1、在windows下下载的压缩文件不要在windows下解压,要在mac os下解,否则里面的链接文件的链接会丢失。

2、尽量在每次make前都要make clean下,不然会出现不必要的错误。


CC= /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv7
CFLAG=-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk

 今天终于搞定了armv7(amv6和amv7s也是一样的道理),两个静态库,libssl.a和libcrypto.a。测试OpenSSL的一个项目是发现如果用5.1SDK编译的.a同样可适用于5.0SDK。


0 0
原创粉丝点击