Question

I use openssl in my ios project and so I build a static library with the build script from github: https://github.com/x2on/OpenSSL-for-iPhone . I included the libcrypto.a and libssl.a in my xcode project and can succesfully use all openssl functions. Now I want to support compression with openssl. The problem: the created library not seem to support any compression method (SSL_COMP_get_compression_methods() is empty).

So I add zlib-dynamic property:

./Configure iphoneos-cross --openssldir="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" zlib-dynamic

I added libz.dylib to the link with section:

http://oi60.tinypic.com/2ljlqmb.jpg

Now the compression works in simulator but not on the device. As far as I know dynamic librarys are not allowed on iOS. However libz.dylib is a system library. Can openssl use the integrated zlib on a device or not? If not, is it possible to use openssl with compression on a iOS device?

Was it helpful?

Solution

You are right, iOS already contains libz.dylib. As such, you should be able to link to it:

  • In "Build Phases" remove libz.dylib you've added;
  • In "Build Settings" locate setting named "Other Linker Flags" and add -lz to it;
  • Note that zlib.h is also available as part of iOS SDK, so no need to have another one.

This should allow your app to be built for both Simulator and the device.

EDIT

The above doesn't resolve the issue. The actual problem is caused by zlib-dynamic OpenSSL Configure. With this option, OpenSSL tries to load libz.so at runtime (and fails to do so because it is named libz.dylib on iOS). This is easy to fix by replacing zlib-dynamic with zlib and re-building OpenSSL. If using newly built library results in linker errors please check the first part of the answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top