De Tout Et De Rien

To content | To menu | To search

Thursday, May 6 2010

Building OpenSSL for iPhone

With the latest iPhone SDK 4.0 release, Apple has introduced the concept of fat binaries to the iPhone/iPad platform. Now, applications for these devices are built for both ARMv6 and ARMv7 architectures.

This has an impact on the third-party libraries you may choose to use, especially the one that don't come with a XCode project; OpenSSL is one of them. This post describes the basic steps to build an universal version of OpenSSL to target the development of iPhone/iPad applications.

Getting OpenSSL

The OpenSSL website only offers source code packages. Be sure to get the latest one, as the library is evolving quickly. At the time of writing, the latest version is the 1.0.0.

Once you got the archive, uncompress it where you want. Open a Terminal and go the uncompressed folder.

As we want to target all the architecture, we need THREE different builds: the simulator (i386), ARMv6 and ARMv7.

Patching OpenSSL

Open the ./crypto/ui/ui_openssl.c file and replace the line

static volatile sig_atomic_t intr_signal;

with

static volatile int intr_signal;

This is because the sig_atomic_t typedef does not exists for iPhone.

Building OpenSSL

Building for the simulator (i386)

Create a folder for the distribution, for example iPhoneSimulator-i386.

Launch the configuration:

./Configure BSD-generic32 --openssldir=iPhoneSimulator-i386

Now, edit the Makefile file and change:

CC= cc

CFLAG= -DOPENSSL_THREADS ...

with

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

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

Once, all this is done, build the OpenSSL:

make; make install

Building for iPhoneOS (ARMv6)

Create a folder for the distribution, for example iPhoneOS-armv6.

Launch the configuration:

./Configure BSD-generic32 --openssldir=iPhoneOS-armv6

Now, edit the Makefile file and change:

CC= cc

CFLAG= -DOPENSSL_THREADS ...

with

CC= /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv6

CFLAG= -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk -DOPENSSL_THREADS ...

Once, all this is done, build the OpenSSL:

make; make install

Building for iPhoneOS (ARMv7)

Create a folder for the distribution, for example iPhoneOS-armv7.

Launch the configuration:

./Configure BSD-generic32 --openssldir=iPhoneOS-armv7

Now, edit the Makefile file and change:

CC= cc

CFLAG= -DOPENSSL_THREADS ...

with

CC= /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv7

CFLAG= -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk -DOPENSSL_THREADS ...

Once, all this is done, build the OpenSSL:

make; make install

Merging OpenSSL

Now that you have the three distinct architecture, a simple way to use them is to merge them.

Create a folder for the distribution, for example iPhoneOS, and two subfolders iPhoneOS/include and iPhoneOS/lib.

Copy the include files from one of the distribution:

@@cp -R iPhoneOS-armv7/include/ iPhoneOS/include

Build a fat binary for each static library:

lipo -create iPhoneSimulator-i386/lib/libcrypto.a iPhoneOS-armv6/lib/libcrypto.a iPhoneOS-armv7/lib/libcrypto.a -output iPhoneOS/lib/libcrypto.a

lipo -create iPhoneSimulator-i386/lib/libssl.a iPhoneOS-armv6/lib/libssl.a iPhoneOS-armv7/lib/libssl.a -output iPhoneOS/lib/libssl.a

Conclusion

The iPhoneOS now contains all you need to develop OpenSSL application for iPhone/iPad.

Friday, December 18 2009

AddDependentFiles Addin updated for Visual Studio 2008

I have update my Visual Studio adding named "Add Dependent Files" (See the original entry). It is available for download here.

Friday, June 19 2009

Citation Mathématique

A la suite de la planche XKCD d'aujourd'hui, ma navigation m'a amenée sur la page Wikipedia du mathématicien Paul Erdös. S'il ne faut en retenir qu'une seule chose, c'est qu'il n'était pas dépourvu d'humour:

"Les premiers signes de la sénilité sont quand un homme oublie les théorèmes. Le deuxième signe, c'est quand il oublie de fermer sa braguette. Le troisième, c'est quand il oublie de l'ouvrir !". Paul Erdös.

Saturday, May 16 2009

How to use a MacBook in closed clamshell with an external display

It is very simple; just follow the instructions of this article:

But there is a gotcha: if you don't connect your MacBook to the power outlet, you will never be able to use the external display.

Wednesday, April 29 2009

Monobjc supports SM2DGraphView framework

Monobjc 2.0.342.0 was released on April 2009, the 15th. One major addition in Monobjc is the support of SM2DGraphView graphing framework. It is the first round to include a graphing framework, and I hope to enhance the support in the next releases.

Sunday, December 21 2008

Sparkle support in Monobjc

Monobjc 2.0.313.0 was released on December 2008, the 17th. One major addition in Monobjc is the support of Sparkle update engine. Sparkle is one of the most used framework in the Cocoa world, as it makes updating an application a breeze. The main problem with Sparkle in Monobjc was the private framework embedding. With Sparkle, updating a Monobjc application has never been so simple. Check out the tutorial for Monobjc and Sparkle.

Saturday, December 13 2008

Monobjc with Delphi Prism

I am pleased to see that Monobjc can be now used with Delphi Prism thanks to RemObjects Software. Marc Hoffman has a nice blog entry about this integration.

Thursday, November 13 2008

<mkbundle/> task in Monobjc

Many people want to package their .NET application for Mac OS X. And above all, they want the experience to be painless, which means that they want to ship an application that runs, whether Mono is installed or not.

The process of packaging a .NET application for Mac OS X basically follows 4 steps:

  • Getting .NET dependencies of the .NET executable
  • Generating a native loader that will embed all the .NET assemblies (.NET executable and .NET dependencies)
  • Getting native dependencies of the native executable
  • Relocating all the stuff so library loading goes well

The process can be even more complicated if you are using reflection, dynamically discovered library and so on. So let's keep thing simple.

Getting .NET dependencies

This is the easy part. You just have to find recursively all the .NET dependencies of the .NET executable. As every .NET assembly contains its references, it is trivial.

Generating a native loader

The native loader generation is simplified by the fact that Mono allows .NET assemblies to be loaded from embedded binary streams. So for every .NET assembly, we generate a binary array and use the magical functions of Mono. If there are configuration files to embed, the process is the same.

Getting native dependencies

Once the native loader is compiled, the otool command can give us all the native dependencies. So we gather all the native library needed to run our application. But on Mac OS X, the dynamic loading is based on paths recorded in each native library. This is the point of the next step.

Relocating all the stuff

This is the tougher part of the packaging. Now that you have all the native dependencies, you must be sure that you only have unique dependencies. Why, because we you gather dependencies, you can find either specific version of a library or compatibility version of a library. Failing to make these reference unique can lead to unexpected behavior (mostly cryptic crashes). That where the otool command is useful as the first line always contains the specific version of a library, even if run against a compatibility version symbolic link. Then the install_name is used to change absolute path to relative path containing the macro @executable_path.

Packaging made easy

All this steps can be tedious and error prone. That's why, in the Monobjc, the packaging is done by a NAnt task: <mkbundle/> (you can find its options on this page). This task can handle most of the need for .NET application packaging in a truly simple way. And as a bonus, this task is not linked to the Monobjc bridge, so you can use it even if you don't use the Monobjc bridge.

Tuesday, November 11 2008

Monobjc 2.0.296.0 has been released

A new release of Monobjc is available. Even if it provides only minor bug fixes, it contains an important work of refactoring of the messaging engine. I will blog on it later.

As usual, Downloads, Tutorials and Samples.

Citation du jour

La citation du jour nous vient de Bruno Kerouanton (excellent blog sur la sécurité informatique):

"La sécurité, tout le monde s’en fout :
- Au boulot, c’est le problème de l’employeur, pas de l’employé.
- A la maison, c’est comme les chiottes. Il y a un PC par maison, toute la famille s’en sert à tour de rôle pour y faire ses besoins quotidiens, et lorsque c’est sale, c’est le dernier qui est passé dessus qui nettoie."

Pas de commentaire.

- page 1 of 10