Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Xcode, how do I link a dynamic library (libcurl) so that the app also works on older versions of the Mac OS?

I am using libcurl in a Mac project built and compiled on OS 10.7 Lion. I can link to the dynamic library just fine, using either the -lcurl option in Other Linker Flags or by adding the library to my project. Everything works as its supposed to.

I'd like the application to work on OS 10.6 and 10.5 as well. I set the deployment target accordingly. When I go to run the application in one of those versions of the OS, I get a dyld error:

Library not loaded: /usr/lib/libcurl.4.dylib Reason: Incompatible library version: X requires version 7.0.0 or later, but libcurl.4.dylib provides version 6.0.0.

It is a similar problem for Mac OS 10.5.

How can I link against the system's libcurl library in Xcode on Mac OS 10.7 so that the application will also run on 10.6 and 10.5?

I've looked at a couple options:

  1. One is to change the Base SDK, as suggested in this post: Mac OS X libcurl dylib compatibility version If I do this, the application works fine. But this is not an option for me. I must be using the 10.7 SDK, so regressing to an older version of the SDK is not acceptable.

  2. I've tried weak linking against the library using the -weak_library /usr/lib/libcurl.dylib option in Other Linker Flags. The application launches but then crashes when I try to reference the libcurl symbols. However, I know it's not a problem with incompatible code because it works when I change the Base SDK.

  3. I've tried dynamically loading the library within code using dlopen("libcurl.dylib", RTLD_LOCAL|RTLD_LAZY); The library seems to load, but I must then manually bind all the symbols I reference?

Surely there must be a way to do this. The libcurl library is installed on Mac OS 10.5, 10.6, and 10.7, but the application fails to use the available library on older versions of the Mac OS. How can I fix this?

like image 847
Philip Avatar asked Apr 26 '12 22:04

Philip


1 Answers

Some options:

  • Switch from libcurl to the Mac framework APIs (CFNetwork, NSURLConnection, etc.)
  • Build and package your own version of libcurl with your app rather than relying on the system library.
  • Copy or symlink the stub library from the SDK corresponding to your deployment target and link to it with an explicit path.
like image 100
Ken Thomases Avatar answered Oct 13 '22 09:10

Ken Thomases