我有一个关于如何配置CMakeLists.txt文件的问题,以便我可以在不使用共享库的情况下在macOS上编译程序,这意味着它可以在另一台macOS计算机上运行而无需安装OpenCV。
我已将set(BUILD_SHARED_LIBS=OFF)
添加到CMakeLists.txt文件中,但是当我通过在终端上键入otool -L ./MyProgram
来检查已编译的程序时,它会显示以下内容:
/usr/local/opt/opencv/lib/libopencv_gpu.2.4.dylib (compatibility version 2.4.0, current version 2.4.13)
/usr/local/opt/opencv/lib/libopencv_contrib.2.4.dylib (compatibility version 2.4.0, current version 2.4.13)
/usr/local/opt/opencv/lib/libopencv_legacy.2.4.dylib (compatibility version 2.4.0, current version 2.4.13)
/usr/local/opt/opencv/lib/libopencv_objdetect.2.4.dylib (compatibility version 2.4.0, current version 2.4.13)
/usr/local/opt/opencv/lib/libopencv_calib3d.2.4.dylib (compatibility version 2.4.0, current version 2.4.13)
/usr/local/opt/opencv/lib/libopencv_features2d.2.4.dylib (compatibility version 2.4.0, current version 2.4.13)
/usr/local/opt/opencv/lib/libopencv_video.2.4.dylib (compatibility version 2.4.0, current version 2.4.13)
/usr/local/opt/opencv/lib/libopencv_highgui.2.4.dylib (compatibility version 2.4.0, current version 2.4.13)
/usr/local/opt/opencv/lib/libopencv_ml.2.4.dylib (compatibility version 2.4.0, current version 2.4.13)
/usr/local/opt/opencv/lib/libopencv_imgproc.2.4.dylib (compatibility version 2.4.0, current version 2.4.13)
/usr/local/opt/opencv/lib/libopencv_flann.2.4.dylib (compatibility version 2.4.0, current version 2.4.13)
/usr/local/opt/opencv/lib/libopencv_core.2.4.dylib (compatibility version 2.4.0, current version 2.4.13)
/opt/X11/lib/libSM.6.dylib (compatibility version 7.0.0, current version 7.1.0)
/opt/X11/lib/libICE.6.dylib (compatibility version 10.0.0, current version 10.0.0)
/opt/X11/lib/libX11.6.dylib (compatibility version 10.0.0, current version 10.0.0)
/opt/X11/lib/libXext.6.dylib (compatibility version 11.0.0, current version 11.0.0)
/usr/local/opt/libpng/lib/libpng16.16.dylib (compatibility version 43.0.0, current version 43.0.0)
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libsqlite3.dylib (compatibility version 9.0.0, current version 253.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 307.4.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)
我猜它没有使用静态OpenCV库编译。 这是我的CMakeLists.txt文件:
cmake_minimum_required(VERSION 3.6)
project(MyProgram)
include(../dlib_19_3/dlib/cmake)
set(SOURCE_FILES
main.cpp
SupportFunction.cpp
SupportFunction.h)
add_executable(MyProgram ${SOURCE_FILES})
target_link_libraries(MyProgram dlib)
set(USE_FAT_OPENCV TRUE)
set(OpenCV_INCLUDE_DIR "/usr/local/Cellar/opencv/2.4.13.1/include/")
include_directories(${OpenCV_INCLUDE_DIR})
set(OpenCV_LIBS "opencv_gpu;opencv_contrib;opencv_legacy;opencv_objdetect;opencv_calib3d;opencv_features2d;opencv_video;opencv_highgui;opencv_ml;opencv_imgproc;opencv_flann;opencv_core")
link_directories(/usr/local/Cellar/opencv/2.4.13.1/lib)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(BUILD_SHARED_LIBS=OFF)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(MyProgram ${OpenCV_LIBS})
我希望你们的回答。感谢您的时间。