ios编译openssl曲折的过程纪录

来源:互联网 发布:现代四大名著网络 编辑:程序博客网 时间:2024/06/04 22:15

转自:http://dingran.iteye.com/blog/1743496

废了两天的劲,还是我笨呢,总算搞定了,希望可以帮助后来者们。

 

1.下载OpenSSL源代码库:

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

 

2.分别编译arm7,ram6和i386的三个架构的静态库。

 

arm7的命令是:

 

执行Config文件:

./configure BSD-generic32 --openssldir=/Users/<用户名>/openssl-1.0.1c/新建的arm7目录

 

增加-DEBUG_SAFESTACK,是为了可以编译出可以Debug的库,试了不好用,希望有人能指点一下。

 

修改Makefile:这个是示意命令,不直接使用

 

CC= /Applications/Xcode\ 4.4.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv7

CFLAG= -DOPENSSL_THREADS -pthread -D_THREAD_SAFE -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DTERMIOS -O3 -fomit-frame-pointer -Wall -isysroot /Applications/Xcode\ 4.4.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk

 

arm6和arm7一样,只是-arch armv7变为-arch armv6即可。

 

最终使用的修订后的命令如下:

 

CC= /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv7

CFLAG= -DOPENSSL_THREADS -pthread -D_THREAD_SAFE -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DTERMIOS -O3 -fomit-frame-pointer -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk

 

i386的是给模拟器用的

 

执行Config文件:

./configure BSD-generic32 --openssldir=/Users/<用户名>/openssl-1.0.1c/新建的i386目录

 

 

修改Makefile:示意而已,先别急

 

CC= /Applications/Xcode\ 4.4.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -arch i386

CFLAG= -DOPENSSL_THREADS -pthread -D_THREAD_SAFE -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DTERMIOS -O3 -fomit-frame-pointer -Wall -isysroot /Applications/Xcode\ 4.4.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk

 

修改后的命令是:

 

CC= /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -arch i386

CFLAG= -DOPENSSL_THREADS -pthread -D_THREAD_SAFE -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DTERMIOS -O3 -fomit-frame-pointer -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk

 

 

实际上我这台机子安装的xcode路径很变态,不是在用户目录下,而是跑到根目录下了,并且Xcode.app目录变成了Xcode 4.4.1.app,这些都对我造成了很大影响,变态,强烈谴责上上个机主。

 

OS版本的sdk路径是:

 

/Applications/Xcode 4.4.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk

 

模拟器版本的sdk路径是:

 

/Applications/Xcode 4.4.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk

 

需要注意的是:/Xcode 4.4.1.app/需要是这样才行:/Xcode\ 4.4.1.app/

这也是最后的疑问,能编译出2个静态库,但是有错误:

 

/bin/sh: /Applications/Xcode\: No such file or directory

make[2]: *** [link_app.] Error 127

make[1]: *** [openssl] Error 2

make: *** [build_apps] Error 1

 

看提示,可能就是这个反斜杠导致的问题!所以我想重新装xcode,直接用最新版本的。

 

 

解决办法:

 

先将Xcode 4.4.1.app文件夹名称修改成Xcode.app,然后路径就使用/Applications/Xcode.app/*,这样就没有空格的干扰了,注意此时的xcode不能使用了,必须在完事后修改回来。mv Xcode.app Xcode\ 4.4.1.app

 

make完毕后会出现如下提示:

 

making all in tools...

make[1]: Nothing to be done for `all'.

 

此时执行make install,编译出的库文件就安装到指定的目录中了。

 

每次编译新一种库都要先清理上次的残留,make clean,但还是会有影响,所以我每次都删除后,解压出新的重新开始。clean失败的原因也跟你mkdir的新文件夹的名字有关系,比如不能是lib*这样的,陷阱真多啊,别的名字也不行,关键是下一级目录中有lib文件夹,遇到后它也停止clean了,变态吧,呵呵。

 

合并3个版本的库:

 

lipo -create libarm7/lib/libssl.a openssl_arm6/lib/libssl.a libi386/lib/libssl.a -output libssl.a

 

lipo -create libarm7/lib/libcrypto.a openssl_arm6/lib/libcrypto.a libi386/lib/libcrypto.a -output libcrypto.a

 

查看生成的库是否正常:

 

lipo -info libssl.a 

Architectures in the fat file: libssl.a are: armv7 armv6 i386

 

lipo -info libcrypto.a 

Architectures in the fat file: libcrypto.a are: armv7 armv6 i386

 

OK,开始使用了,这回可是正确的库了,强烈鄙视openssl的团队,编译出错还能出库,库也不好用,害死我了,靠。


0 0
原创粉丝点击