Deploy and distribute OpenCV applications with Xcode4 on Mac OSX

前端 未结 2 1248
闹比i
闹比i 2020-12-31 22:13

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?

相关标签:
2条回答
  • 2020-12-31 22:19

    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,

    0 讨论(0)
  • 2020-12-31 22:25

    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.

    0 讨论(0)
提交回复
热议问题