7

I'm working on an OpenCV application and my question is how can I deploy and distribute the application on non-development-machines, machines where OpenCV isn't installed?

I'm using Xcode4 on Mac OS X Lion with OpenCV 2.2.

thanks

sn3ek
  • 1,929
  • 3
  • 22
  • 32
  • if the solution doesn't help you, can you explain us better what you expect ? thanks a lot, Julien – jmartel Jul 29 '11 at 14:04

2 Answers2

5

This is only a partial answer because I also haven't yet figured out how to do this with the OpenCV libraries. (Figured it out. See update below.) But I have done it with other libraries (SM2DGraphView).

There are three things that need to happen:

  1. You need to copy the OpenCV libraries that your program uses into the application bundle. To do that (in Xcode 3, anyway), add a Copy Files build phase to your target. Drag the library files from Xcode's file list onto the build phase. Double-click the Copy Files item and set the destination to Frameworks.

    Note that you need to make sure that the library you include in your Xcode project is a library file and not a symlink to a library file. Otherwise only the symlink will be copied to your application bundle.

  2. The install path of the OpenCV framework files needs to be set to @executable_path/../Framework. If the framework was being built in Xcode, you'd do this in the project settings. Since OpenCV is not being built in Xcode you need to do it after the fact with the install_name_tool command line program: install_name_tool -id @executable_path/../Frameworks libopencv_imgproc.2.3.1.dylib. You should be able to set this up in a Run Script build phase in your target.

  3. The executable needs to find the library in the bundle's Frameworks directory. This is where I'm currently stuck.

Update

I found the correct install_name_tool commands to get the program to see the libraries (and the libraries to see the other libraries). The information on the Qt page for deploying OS X programs was the key.

I ran otool -L on the executable file in my program's Contents/MacOS directory and saw this [non-relevant lines removed]:

lib/libopencv_core.2.3.dylib (compatibility version 2.3.0, current version 2.3.1)
lib/libopencv_imgproc.2.3.dylib (compatibility version 2.3.0, current version 2.3.1)
lib/libopencv_highgui.2.3.dylib (compatibility version 2.3.0, current version 2.3.1)

So I used these commands (while in the Contents/MacOS directory) to get the program to look in the right place for the libraries:

install_name_tool -change lib/libopencv_core.2.3.dylib @executable_path/../Frameworks/libopencv_core.2.3.1.dylib CocoaCVTest 
install_name_tool -change lib/libopencv_imgproc.2.3.dylib @executable_path/../Frameworks/libopencv_imgproc.2.3.1.dylib CocoaCVTest 
install_name_tool -change lib/libopencv_highgui.2.3.dylib @executable_path/../Frameworks/libopencv_highgui.2.3.1.dylib CocoaCVTest 

Then I changed to the Contents/Frameworks directory and used these commands to tell the libraries where they were installed:

install_name_tool -id @executable_path/../Frameworks/libopencv_core.2.3.1.dylib libopencv_core.2.3.1.dylib
install_name_tool -id @executable_path/../Frameworks/libopencv_imgproc.2.3.1.dylib libopencv_imgproc.2.3.1.dylib
install_name_tool -id @executable_path/../Frameworks/libopencv_highgui.2.3.1.dylib libopencv_highgui.2.3.1.dylib

Now the imgproc library needs to be told where to find the core library and highgui needs to be told where to find core and imgproc:

install_name_tool -change lib/libopencv_core.2.3.dylib @executable_path/../Frameworks/libopencv_core.2.3.1.dylib libopencv_imgproc.2.3.1.dylib
install_name_tool -change lib/libopencv_core.2.3.dylib @executable_path/../Frameworks/libopencv_core.2.3.1.dylib libopencv_highgui.2.3.1.dylib 
install_name_tool -change lib/libopencv_imgproc.2.3.dylib @executable_path/../Frameworks/libopencv_imgproc.2.3.1.dylib libopencv_highgui.2.3.1.dylib 

I'm still running into an issue where highgui is looking for a lot of libraries in /opt/local/bin but I'm fairly confident that the OpenCV part of the problem is solved. Now I just need to get all these commands into a build phase in Xcode.

SSteve
  • 10,550
  • 5
  • 46
  • 72
1

What i would advise is to use a cross platform compilation builder (like an improved autotool). A very common one is CMake which is not so easy to handle but not so difficult, not only a common one, it is used by OpenCV...

  • 1) Write your application on your development machine and write a Cmake (don't forget to write a part to use the OpenCV Cmake)

  • 2) Provide your cmake files and the opencv library to the non-development machine

  • 3) Build with CMake script the application on the target platform, if you wrote it correctly it can build opencv (using the own OpenCV Cmake), and build your application (with the one you wrote)

If you want to go further, you can create an install wizard or a package with CPack in order to automatize everyting.

Here is the link where you can download it

Julien,

jmartel
  • 2,771
  • 4
  • 24
  • 27
  • Thanks, I will try this. But I want to deploy the application for non-tech people. I've read that it should be possible to copy the library files into the app folder to distribute it on machines without OpenCV. But this doesn't work for me... :( – sn3ek Jul 29 '11 at 17:57
  • For sure, if you do a script and use an installer wizard, i don't see why it wouldn't be for non-tech people... At least if they know how to click on next, it should be enough :p – jmartel Aug 01 '11 at 17:27
  • 1
    There's no need to have the end user install the libraries separately. OS X allows libraries to be embedded in the application bundles. This is the "correct" approach on the Mac. It eliminates external dependencies and ensures that the expected versions of the libraries are the ones being used. – SSteve Aug 09 '11 at 15:59
  • @SSteve this is exactly what I meant. In the last days I hadn't time to test the other approaches. How do I embed the libraries to may product with Xcode4.1? – sn3ek Aug 10 '11 at 16:23
  • @sn3ek Take a look at my answer. That's the first step. Unfortunately I haven't figured out all the rest of the steps yet. I haven't been able to work on it in the past couple weeks. I think `otool` will be instrumental in solving this. If you change into your app's /Contents/MacOS directory and run `otool -L _yourappname_` you'll see the libraries it uses. Somehow we need to get it to look for the OpenCV libraries in the app's Frameworks directory instead of lib/_xxx_.dylib – SSteve Aug 10 '11 at 16:34
  • Good, for sure it is nice to use apple tools to do apple things and what if your client is on Windows ? – jmartel Aug 10 '11 at 16:47
  • The problem is that I'm programming a vst plugin, so it's not runnable only buildable. That's why this answers around does not work for my problem :( But they work for runnable applications on mac os x. – sn3ek Sep 08 '11 at 14:02