问题
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:
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.
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.
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?
回答1:
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.
来源:https://stackoverflow.com/questions/10342046/in-xcode-how-do-i-link-a-dynamic-library-libcurl-so-that-the-app-also-works-o