How to Include Openssl on an iOS Project in a Way That Works

How to add OpenSSL to an Xcode project

You will need to compile and link it yourself, and your app needs to ship it. If the license of your app and OpenSSL's license are compatible, you may use static linking. Otherwise you will need to dynamically link it.

There are a few documents describing the process and build scripts that you can find with Google searches. For iOS, there's even a Github project. I didn't copy the contents of those documents here since it's too much and it's a moving target.

You can also install OpenSSL with Homebrew. If you just want to have your app run on your Mac and you don't want to distribute it, this is the easiest way: you just need to link it. But if you want to distribute your app, you would need to copy the library/libraries to your app bundle and make sure the the linker finds it there. This also has the disadvantage that there's a possible "disconnect" between your app and the OpenSSL version: if in one year, you update OpenSSL with Homebrew and want to compile/link an older version of your app against the very same OpenSSL version as you've used at that time, you have a problem.

How to include OpenSSL on an iOS project in a way that works

The easiest solution would be to use CocoaPods - there is an OpenSSL pod...

Installing OpenSSL library for Xcode

OK, how to build and install it....

It might be easier to use a pre-built version of OpenSSL for iOS. You can find one at this Github account. The OpenSSL from that Github are multi-arch. They have ARMv7, ARMv7s, ARM64, and i386. That means they work with devices and simulators.

Download either OpenSSL 1.0.1e or 1.0.1f. Install it in a location like /usr/local/ssl/ios.

Then, add the headers to your Xcode project. They are located in /usr/local/ssl/ios/include:

Sample Image

Finally, add the multi-arch libs (libcrypto.a and libssl.a) to your Xcode project. They are located in /usr/local/ssl/ios/lib:

Sample Image

Using OpenSSL cocoa pod in iOS project

1) I have created sample project

2) Added pod 'OpenSSL', '~> 1.0'
3) Closed project and then opened Project_Name.xcworkspace

4) used #import <OpenSSL/bio.h>
5) Command + Shift + K (for cleaning project)

6) Command + Shift + B (for building it)

It worked for me on Xcode7.2. Try this.

XCode can't find OpenSSL headers in /usr/include

Xcode uses the currently selected SDK as a base path, which it prefixes on to system includes. So if your SDK is /Developer/SDKs/MacOSX10.6.sdk then it will look under /Developer/SDKs/MacOSX10.6.sdk/usr/include by default for system includes.

There are various possible workarounds - I would probably just put a symbolic link in /Developer/SDKs/MacOSX10.6.sdk/usr/include pointing at /usr/include/openssl but you can probably think of others now that you know the underlying problem.



Related Topics



Leave a reply



Submit