简体   繁体   English

使用包括 OpenCV 在内的 cmake 构建用于分发的 MacOS 可执行文件

[英]Building a MacOS executable for distribution using cmake including OpenCV

I have a cmakelists.txt file that compiles my MacOS application using OpenCV, C++, OpenGL, based on information I found on SO.我有一个 cmakelists.txt 文件,它根据我在 SO 上找到的信息使用 OpenCV、C++、OpenGL 编译我的 MacOS 应用程序。 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.当我尝试将可执行文件的文件夹复制到另一台 Mac 时,由于缺少 OpenCV 库而出现错误,预期在与我的可执行文件不同的文件夹中。

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?是否可以对文件进行更改,以便将 OpenCV 编译代码包含在可执行文件或其文件夹中以进行分发? For what it's worth I am using CMake because I could not figure out a simpler way to get it to build.对于我使用 CMake 的价值,因为我无法找到一种更简单的方法来构建它。

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)

On another question related: Static OpenCV compile关于另一个相关问题: 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:现在对于find_library( OPENGL_FW OpenGL ) ,您需要更加明确:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM