首先,写一些 简单 的cmake .
如下:
cmake_minimum_required (VERSION 2.6)
add_compile_options(-std=c++11)
set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/libs/opencv-install/lib/pkgconfig")
find_package(PkgConfig REQUIRED)
pkg_search_module(PKG_OPENCV REQUIRED opencv)
add_executable(testopencv testopencv.cpp)
include_directories(${PKG_OPENCV_INCLUDE_DIRS})
target_link_libraries (testopencv ${PKG_OPENCV_LDFLAGS})
1.说明:
a. 这是程序编译后 的名字:
testopencv
b. cpp 文件名是这个:
testopencv.cpp
c . 怎么知道并链接 opencv 的库 ?? :
set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/libs/opencv-install/lib/pkgconfig")
find_package(PkgConfig REQUIRED)
pkg_search_module(PKG_OPENCV REQUIRED opencv)
include_directories(${PKG_OPENCV_INCLUDE_DIRS})
target_link_libraries (testopencv ${PKG_OPENCV_LDFLAGS})
d . 这样做的 好处? cmake 之后,可以makefile ,make ,make clean 了。
第二天: 附上一个链接:
这里说的 比较详细。