0
votes

I have an iOS app, which use liblzma. I am currently able to successfully write cross platform compile script to compile the source code into a .a file, and use the .a with headers in my project.

Now in iOS 8 and above, Apple start to support dynamic linking, so I was curious to see if I am able to use liblzma.dylib in my project instead of liblzma.a. But I failed.

Here's what I have done:

  1. modify the compile script I previously used to compile liblzma.a. I changed --disable-shared to --enable-shared, and then use lipo to combine .dylib of each arch to a fat .dylib.

  2. I removed the liblzma.a from my project, and added liblzma.dylib to my project

  3. Build, success. But when running on device, I encountered the following error

dyld: Library not loaded: /Volumes/Data/Developer/build/xz-5.2.2/build/iOS/arm64/lib/liblzma.5.dylib Referenced from: /var/containers/Bundle/Application/AB7A063F-9C3F-4CEB-A757-965238947000/****.app/**** Reason: Incompatible library version:**** requires version 8.0.0 or later, but liblzma.5.dylib provides version 6.0.0 (lldb)

  1. I used tool to check the actual version of the newly built .dylib, this is what I got

/Volumes/Data/Developer/build/xz-5.2.2/build/iOS/Universal/lib/liblzma.5.dylib: /Volumes/Data/Developer/build/xz-5.2.2/build/iOS/x86_64/lib/liblzma.5.dylib (compatibility version 8.0.0, current version 8.2.0) /usr/lib/libSystem.dylib (compatibility version 1.0.0, current version 1226.10.1)

I have a few questions:

  • Can I add dylib like this?
  • Is liblzma.dylib actually copied to my iOS device when I run the app?
  • Why the error message said liblzma.5.dylib provides version 6.0.0 whereas otool shows current version 8.2.0?
  • I know for iOS 8.0+ apps to use dylib, that dylib also need to be signed. How do I do that?

Thanks!

1
are you trying it on emulator? did you check if the device already have the library? maybe you library does not being copied to the proper directory and therefore the standard one from the iPhone is being used? Did you remove all instances of .a from the project? Can you try to run it with the debugger to see what is happening? - Igor
some things to consider: you need a universal architecture library which supports x64 as well as ARM. Your version compiled and linked on the OSX appears to be x86_64 and seems to conflict with the one you are setting as Universal. I don't remember how its done, but I know it can be done (I've done it for a framework) but you have to manually set cross-compilation for it. Isn't lzma officially supported? From your errors, its seems that lldb has a different version of the library whereas for iOS its yet another. - Ælex
@Igor Running on emulator also doesn't work, same error. I don't know if the system have the library. Yes, I think I have removed all appearance of .a. I am already running with the debugger, that's where I got the error message. - Automatic
@Automatic, so is .dylib bundled with you application? - Igor
@igor The dylib is definitely in General->Linked frameworks and libraries and also in Build Phase->Link binary with libraries - Automatic

1 Answers

0
votes

Solved!

  • Yes, i could load dylib like that
  • I need to add copy file build phase for the dylib to be copied
  • when liblzma.dylib is not copied, iOS seems to use a liblzma.dylib already on device, which has lower version number than required
  • I need to modify install name of the dylib using install_name_tool