Search code examples
iphonebackwards-compatibilitydylib

How to specify compatibility version for dylib in iPhone projects?


I recently added a static library (mobclix) to my iPhone project which required me to set the Base SDK to 3.0. This library is claimed to be compatible with 2.2 and so far it looks like it's true. I set the project's Deployment Target to 2.2. No problems there.

Now, I am also using libxml2 in this same project. Apparently, the libxml2.2.dylib in OS 3.0 is newer than in OS 2.X (version 10 and 9 respectively). However, my code that uses libxml2, was already compatible with the libxml2 version included with OS 2.X. Since I needed to set the Base SDK to 3.0, the "compatibility version" / minimum version requirement / dependency is automatically set to the newer version of libxml2. When I try to run the app in OS 2, I get this runtime error (obviously):

  Dyld Error Message:
  Library not loaded: /usr/lib/libxml2.2.dylib
  Referenced from: /Users/Martijn/Library/Application Support/iPhone Simulator/User/Applications/4D5456DE-F297-4DF4-ACA6-DA8BBBBBA914/Luisterpaal.app/Luisterpaal
  Reason: Incompatible library version: Luisterpaal requires version 10.0.0 or later, but libxml2.2.dylib provides version 9.0.0

Is it possible to override the version requirement somewhere? Or other ideas to solve this issue?


Solution

  • The compatibility version is set according to the version embedded in the dylib of the current SDK during build. I have not found a way to change or override this.

    However, in the target in Xcode under the "Link with binary with libraries" branch there is an option to link a dylib "weakly". This skips version checking at the time of loading the dylib (runtime). It's your responsibility then to only make calls to existing functions. Making calls to non-existent functions will crash the application.