玩命加载中 . . .

CMakeForOpenCV


g++ 编译 OpenCV

g++ main.cpp -I D:/software/opencv/opencv/build/x64/mingw/install/include 
-L D:/software/opencv/opencv/build/x64/mingw/install/x64/mingw/lib 
-l libopencv_calib3d450 -l libopencv_core450 -l libopencv_dnn450 -l libopencv_features2d450 
-l libopencv_flann450 -l libopencv_gapi450 -l libopencv_highgui450 -l libopencv_imgcodecs450 
-l libopencv_imgproc450 -l libopencv_ml450 -l libopencv_objdetect450 -l libopencv_photo450 
-l libopencv_stitching450 -l libopencv_video450 -l libopencv_videoio450 -l libopencv_world450 
-o main.exe 

Ubuntu可以用 pkg_config

查看OpenCV路径和库

$ pkg-config --cflags --libs opencv 
-I/usr/local/include/opencv 
-I/usr/local/include 
-L/usr/local/lib 
-lopencv_dnn -lopencv_ml -lopencv_objdetect 
-lopencv_shape -lopencv_stitching -lopencv_superres 
-lopencv_videostab -lopencv_calib3d -lopencv_features2d 
-lopencv_highgui -lopencv_videoio -lopencv_imgcodecs 
-lopencv_video -lopencv_photo -lopencv_imgproc 
-lopencv_flann -lopencv_viz -lopencv_core

g++ main.cpp -o main `pkg-config --cflags --libs opencv`

CMake 编译 OpenCV

find_package(OpenCV REQUIRED)

message("${OpenCV_INCLUDE_DIRS}")
# /usr/local/include

message("${OpenCV_LIBRARY_DIRS}")
# /usr/local/include/opencv

message("${OpenCV_LIBS}")
# opencv_calib3d;opencv_core;...

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

set(CMAKE_BUILD_TYPE Debug)

# 头文件目录
include_directories(${OpenCV_INCLUDE_DIRS})

# 库文件目录
link_directories(${OpenCV_LIBRARY_DIRS})


add_executable(main main.cpp)

#链接
target_link_libraries(main ${OpenCV_LIBS})

文章作者: kunpeng
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 kunpeng !
  目录