1

I have a cmakelists.txt file that compiles my MacOS application using OpenCV, C++, OpenGL, based on information I found on SO. When I try copying the folder of the executable to another Mac, I get an error due to missing OpenCV libs, expected in a different folder from my executable.

Is there a change I can make to the file so that it will include the OpenCV compiled code in the executable, or its folder for distribution? For what it's worth I am using CMake because I could not figure out a simpler way to get it to build.

cmake_minimum_required( VERSION 3.1 )
project( go)
set (CMAKE_CXX_STANDARD 11)
find_package( OpenCV REQUIRED )
find_library( COCOA_FW Cocoa )
find_library( OPENGL_FW OpenGL )
find_library( IOKIT_FW IOKit )
add_executable( go main.cpp gl_utils.cpp user_interface.cpp geometry_2d.cpp)
target_include_directories( go PRIVATE ${CMAKE_SOURCE_DIR}/include )
target_link_libraries( go ${OpenCV_LIBS} ${COCOA_FW} ${OPENGL_FW} ${IOKIT_FW} ${CMAKE_SOURCE_DIR}/common/libGLEW.a ${CMAKE_SOURCE_DIR}/common/libglfw3.a)
Kevin
  • 16,549
  • 8
  • 60
  • 74
Jon R
  • 13
  • 5
  • After searching more I think [this question](https://stackoverflow.com/q/42781748/7520754)'s comments are a starting point, and I might need to follow [this guide](https://blogs.wcode.org/2014/10/howto-install-build-and-use-opencv-macosx-10-10/) to get static OpenCV libraries installed. Will update if I solve it. – Jon R Aug 19 '19 at 23:05
  • Hey, @Jon R, did you progress with the static links for mac? – gcstr Jan 04 '20 at 23:42
  • Besides linking against static OpenCV, you could also bundle the OpenCV (dylib) libraries you are dependent on along with your executable, and change your executable and anything else that depends on them to reference them using a relative path using `install_name_tool`. Use `otool -L ` to figure out what to bundle, and be sure to follow the dependency chain to bundle sub-dependencies. – ThatOneDude Jan 11 '20 at 00:59

1 Answers1

2

On another question related: Static OpenCV compile

set(OpenCV_STATIC ON)
find_package(OpenCV REQUIRED)

Now for the find_library( OPENGL_FW OpenGL ), you will need to be more explicit:

# This could change based on the OpenGL library you have installed.
find_library( OPENGL_FW libGL.a )
Vi1i
  • 100
  • 9