11

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?

Community
  • 1
  • 1
Philip
  • 655
  • 8
  • 12

1 Answers1

7

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.
Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • Thanks Ken. The first option won't work. I've running FTP through SSL and neither CFNetwork nor NSURLConnection supports it. That was definitely the first place I looked. =) I'd definitely prefer to avoid packaging my own version of libcurl with the app, so I'm going to look into symlinking the stub. My concern is that I'm targeting 10.5, and I don't even know if that SDK is available for Xcode 4.3 on Lion. – Philip Apr 27 '12 at 02:14
  • 1
    I'm marking your answer as correct and recommending other users follow the 3rd option. A working solution is in fact to acquire a previous version of the SDK and copy the libcurl.4.dylib from it into the 10.7 SDK directory -- which is now contained inside the Xcode application package. You should back up the original first. Xcode links against that version of the library while providing you with headers for the newer version in 10.7. This means that the application should check for the availability of symbols before using them in code. – Philip Apr 27 '12 at 17:26