Linking to libcrypto for Leopard?
Asked Answered
S

5

11

I am using Mac OS X 10.6 SDK and my deployment target is set to Mac OS 10.5. I'm linking to libcrypto (AquaticPrime requires this) and found out that my app doesn't launch on Leopard. The error is

dyld: Library not loaded: /usr/lib/libcrypto.0.9.8.dylib

I've tried the following workarounds but none of them work:

  • Linking directly to libcrypto.0.9.7.dylib (the 10.6 SDK refuses to link directly with libcrypto.0.9.7.dylib.
  • Copying the 10.5 SDK's version of libcrypto.0.9.7.dylib to the 10.6 lib directory and try t link with it (this time the link process succeeded but in Leopard the app still tries to lookup the non-existent libcrypto.0.9.8.dylib file and thus won't launch).
  • Copying libcrypto.0.9.7.dylib from a Mac OS X 10.5.8 installation and link with it (the link was successful but the app still looks for libcrypto.0.9.8.dylib).

Is there a way to link to this library and still use the 10.6 SDK?

Thanks.

Slipway answered 11/4, 2010 at 10:41 Comment(1)
Describe how you are linking to the library. I'm using this just fine, as are others, so either something is wrong with your installation or you're linking incorrectly.Javelin
E
1

You could try setting the base SDK to 10.5 in your target build settings.

Embosom answered 14/4, 2010 at 11:20 Comment(6)
Yes.. this one worked. I set the base SDK to 10.5 but set the active SDK to 10.6. This way I have 10.6 source codes (e.g. those that implement 10.6 protocols) and still able to run the app in 10.5. Thanks.Slipway
Now that the "Active SDK" option is removed in XCode 3.2.3, what should I do for this issue?Slipway
You are a bit limited in options now. The issue occurs because the 10.6 SDK has an version of libcrypto in it that is incompatible with the one that ships in 10.5. By setting the base SDK to 10.5, you are saying that it is the maximum SDK version you are going to use. Technically, you shouldn't be using 10.6 headers.Embosom
The nice thing is that now in XCode 3.2.3, I can use the 10.6 SDK and yet link to the libcrypto in 10.5 SDK. So is the new workaround for XCode 3.2.3.Slipway
@Embosom Are you sure this answer is still current?Waller
The 10.7 version of libcrypto is still 0.9.8. So it's probably still current. However, it's possible that Xcode no longer supports 10.5.Embosom
E
22

As per this thread here ( first post in thread: http://lists.apple.com/archives/cocoa-dev/2009/Aug/msg01737.html , "libcrypto on Snow Leopard" thread listing: http://lists.apple.com/archives/cocoa-dev/2009/Aug/thrd19.html ), I believe the solution is to do the following:

  1. Go to /Developer/SDKs/MacOSX10.5.sdk/usr/lib/ . From this folder, copy "libcrypto.0.9.7.dylib" to your project source folder.

  2. Rename the file you just copied to "libmycrypto.dylib".

  3. Add the file you just renamed to your project. Make sure to remove any other linked libcrypto frameworks from your project.

  4. Go through your build settings, and make sure you remove the "-lcrypto" linker flag. (It's usually put in the "Other Linker Flags" setting.)

Now you should be able to build your project and it will work on both 10.5 and 10.6.

(libcrypto.0.9.7 is available on both 10.5 and 10.6. The file you copied is just a stub of the headers, but you're just linking against it, not embedding it in your project. Since the linker uses the install path not the actual filename of the dylib, naming it "libmycrypto.dylib" eliminates path conflicts, but still allows you to link against the library you need.

FWIW, this is an Xcode problem. You should be able to link against /usr/lib/libcrypto.dylib -- the symbolic link -- and have it target the correct version of libcrypto on both 10.5 and 10.6. However, Xcode always seems to link to version 0.9.8 when building on Snow Leopard for some reason.)

Erida answered 12/4, 2010 at 8:28 Comment(3)
Great answer, just what I was looking for. Cheers.Cotton
If you want build your app on 10.6+, but run it on 10.5, this is the answer you should use (not the one checked above.) Also: when you're looking for -lcrypto linker flags, remember that they can be in both the project level settings as well as the individual targets. Make sure you remove ALL of them.Exteriorize
Maybe this will work with ObjectiveC, but not with C++/gcc. Only use of 10.5 SDK via -isysroot option worked to link against 0.9.7 versions of libssl/libcrypto - you need not only to LINK against those dylibs, but COMPILE using their H files of 0.9.7. Also when building on 10.7/10.8 using 10.5 SDK, deep in STL headers of 10.5 SDK, there are symlinks like i686-apple-darwin10 pointing to i686-apple-darwin9. You need to create such symlinks for darwin11 and darwin12 (for both i686 and x86_64). To be precise, directory with those symlinks is /MacOSX10.5.sdk/usr/include/c++/4.2.1.Dumpcart
E
1

You could try setting the base SDK to 10.5 in your target build settings.

Embosom answered 14/4, 2010 at 11:20 Comment(6)
Yes.. this one worked. I set the base SDK to 10.5 but set the active SDK to 10.6. This way I have 10.6 source codes (e.g. those that implement 10.6 protocols) and still able to run the app in 10.5. Thanks.Slipway
Now that the "Active SDK" option is removed in XCode 3.2.3, what should I do for this issue?Slipway
You are a bit limited in options now. The issue occurs because the 10.6 SDK has an version of libcrypto in it that is incompatible with the one that ships in 10.5. By setting the base SDK to 10.5, you are saying that it is the maximum SDK version you are going to use. Technically, you shouldn't be using 10.6 headers.Embosom
The nice thing is that now in XCode 3.2.3, I can use the 10.6 SDK and yet link to the libcrypto in 10.5 SDK. So is the new workaround for XCode 3.2.3.Slipway
@Embosom Are you sure this answer is still current?Waller
The 10.7 version of libcrypto is still 0.9.8. So it's probably still current. However, it's possible that Xcode no longer supports 10.5.Embosom
B
1

Depending on what you're using the lib for, you might be able to replace libcrypto with CommonCrypto which works well with both 10.5 and 10.6. I've used libcrypto only for the MD5 function, so I replaced openssl/md5.h with CommonCrypto/CommonDigest.h and MD5() with CC_MD5(), and libcrypto with CommonCrypto, and now it works on both Leopards.

Blowzed answered 29/9, 2010 at 18:27 Comment(0)
B
0

Have you tried linking against libcrypto.0.9.dylib or libcrypto.dylib instead of the specific versions?

Baptista answered 11/4, 2010 at 22:23 Comment(1)
Yes. - linking to libcrypto.0.9.dylib causes linker errors - linking to libcrypto.dylib links and builds just fine but the app fails to launch in Leopard.Slipway
G
0

Leopard OS X ships with a libcrypto and libssl that only has the ppc architecture.

A simple solution that doesn't require changing the code of the app is to backup your libcrypto.0.9.dylib, libcrypto.0.9.8.dylib, libssl0.9.dylib, libssl.0.9.8.dylib and copy over the libcrypto.0.9.7.dylib and libssl.0.9.7.dylib.

You can use Terminal.app to make these changes in your Applications folder:

  cd /usr/lib
  sudo cp libcrypto.0.9.dylib libcrypto.0.9.dylib.old
  sudo cp libssl.0.9.dylib libssl.0.9.dylib.old
  sudo ln -sf libcrypto.0.9.7.dylib libcrypto.0.9.dylib
  sudo ln -sf libssl.0.9.7.dylib libssl.0.9.dylib

Here's an alternative solution that lets you stay on the freshest openssl version:

  1. reactivate the current openssl: port activate [email protected]_0 (or whatever)
  2. clean up your old unwanted versions of everything: port uninstall inactive
  3. uninstall badly behaved ports: port uninstall md5sha1sum subversion neon
  4. get them back: port install subversion md5sha1sum
Gnathic answered 16/5, 2012 at 12:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.