2
votes

What I have tried

I am working sample application using Caffe model in MAC OSX. I downloaded Caffe source from https://github.com/BVLC/caffe. Steps:

1.Installed dependencies packages for caffe as said in Caffe Link. Some packages is in /usr/local/lib and some packages /opt/local/lib

2.Builded shared library(SO) file using CMakeLists.txt in CMake GUI.

3.Created sample c++ application

4.Linked all dependencies and caffe library files with c++ application.

  1. Built the application

After I executed the application, It needed library files of dependencies package from /usr/local/lib

What I want

After I installed caffe dependencies, I copied all library files in another location.

How to link specified location of the library files in Cmake.?

In Mac osx, when the application run, It takes the library form /usr/local/lib not in the current folder(application folder).

How do I set the application to take library files from current folder.?

1
Are these caffe dependencies dynamic libraries (have the .dylib suffix)?dmedine
My understanding is that in OSX, dynamic libraries are stamped with their path so that when you build your application it will search in that location. You can change that with install_name_tool, but you want to do that before you build, otherwise the app will look in the wrong location.dmedine
And now that I think about it, does mac use .so files? I thought it just did .dylib...dmedine
Thanks for your answer. All dynamic library extension had .dylib. I tried "install_name_tool".But i did not got it . Give sample for changing lib path using "install_name_tool".?balajichinna

1 Answers

1
votes

Here is a command from a makefile that I use to make an OSX application (the names have been changed to protect the innocent):

install_name_tool -id "@executable_path/../Resources/libMyLib.dylib" ./libMyLib.dylib

You can also just run install_name_tool on the command line.

The first argument after -id is the destination you want (including the name of the library) and the second is the current path to the library -- ie the binary itself. In this example the library is in the same folder as the makefile.

Then, after I build the app (the linker will include this new path to the desired library in the binary you build) I copy the library to the Resources folder:

cp ./libMyLib.dylib App.app/Contents/Resources/

In OSX-land @executable_path is whatever directory your actual binary is in. The way apps are packaged is like this: App.app/Contents/MacOS/App. There is also a folder in App.app/Contents called Resources, and this is generally where I stash dependencies if I don't want the user to have to install them him/herself. Thus, in this case, @executable_path/../Resources is a relative path from the app's binary to where the dylib is going to be.

You can used install_name_tool to put the library anywhere you want. I just feel like this is a good place to do it.

By the way, you can check what the current id of the library is with otool -L. Probably, if you run

> otool -L caffe.dylib

it will return something like /usr/local/lib, even if you move it somewhere else. Try to change the id with install_name_tool -id and then run otool -L again, and see what happens. It should make sense at that point.