OS X is a popular platform for data scientists to use for analyzing data. You get the same advantages as other *nix platforms (e.g., easy to use scripting languages) but also gain access to great tools such as Microsoft Excel or the soon-to-be-available Tableau Desktop.

Here’s a tip for OS X to resolve conflicts between multiple dependent libraries. Consider a library L1 which loads a dependent library L2. If L2 is also required by another component outside of your control, you may have difficulties reconciling multiple versions of L2. The key is a tool called install_name_tool. This can be used either 1) to change the internal name of a .dylib file or 2) to change the default lookup paths to dependent libraries. Using this, we can eliminate the need to specify library lookup paths using the DYLD_LIBRARY_PATH variable.

Here’s how:

  1. In your Makefile, when linking, add –headerpad_max_install_names so that the binary gets built with extra space for changing paths with install_name_tool.
  2. Change the binary’s internal name. Use install_name_tool –id to change the internal name (not the name on the file system!)
  3. Change the paths to dependent libraries:
    install_name_tool –change <path to dependent library. This is the exact path returned by otool –L, surrounded in quotes> @loader_path/<dependent_library_name> <library file name (not dependent name)>
  4. Copy dependent libraries to the same directory as the library.
  5. Make dependent libraries writable.
  6. Repeat steps 2 and 3 for each dependent library. For example, say your library depends on OpenSSL 1.0.0. Then you need to change libssl.1.0.0.dylib’s name so execute step 2 on it. It also depends on libcrypto.1.0.0.dylib, so you need to repeat step 3 on it.
  7. Remove the writable flag on dependent libraries.

The @loader_path macro lets you use a path relative to the binary. There’s an @executable_path macro which is the path relative to the binary loading the library. We don’t want to use this.