cmake 引入opencv4

原文件在slam2的ch5/stereo 

 

#查找某个库的包
find_package(Pangolin REQUIRED)

#设置包的路径变量
set(ENV{PKG_CONFIG_PATH} /usr/local/lib/pkgconfig)
#查找pkconfig下的所有包
find_package(PkgConfig REQUIRED)
#查找pkconfig下的opencv4.pc
pkg_search_module(PKG_OPENCV REQUIRED opencv4)

#PKG_OPENCV相关头文件/库的输出
MESSAGE(STATUS "PKG_OPENCV_FOUND:          ${PKG_OPENCV_FOUND}")			#有没有找到		    eg: -- PKG_OPENCV_FOUND:        1
MESSAGE(STATUS "PKG_CONFIG_EXECUTABLE:     ${PKG_CONFIG_EXECUTABLE}")		#pkg-config脚本路径	 eg:  /usr/bin/pkg-config
MESSAGE(STATUS "PKG_CONFIG_VERSION_STRING: ${PKG_CONFIG_VERSION_STRING}")	#pkg-config版本号	  相当于执行: pkg-config --version

MESSAGE(STATUS "PKG_OPENCV_VERSION:        ${PKG_OPENCV_VERSION}")			#opencv的版本		  相当于执行: pkg-config opencv --modversion
MESSAGE(STATUS "PKG_OPENCV_PREFIX:         ${PKG_OPENCV_PREFIX}")			#opencv的安装路径PREFIX

MESSAGE(STATUS "PKG_OPENCV_INCLUDE_DIRS:   ${PKG_OPENCV_INCLUDE_DIRS}")		#头文件路径		    include路径,多个,分开
MESSAGE(STATUS "PKG_OPENCV_LIBRARY_DIRS:   ${PKG_OPENCV_LIBRARY_DIRS}")		#动态库路径		    lib路径,多个,分开
MESSAGE(STATUS "PKG_OPENCV_LIBRARIES:      ${PKG_OPENCV_LIBRARIES}")		#有那些动态库?        相当于执行: pkg-config opencv --libs-only-l,只列出库名字
MESSAGE(STATUS "PKG_OPENCV_LDFLAGS:        ${PKG_OPENCV_LDFLAGS}")			#所有需要链接的标志	  相当于执行: pkg-config opencv --libs,不仅有库名字,还有其路径
MESSAGE(STATUS "PKG_OPENCV_LDFLAGS_OTHER:  ${PKG_OPENCV_LDFLAGS_OTHER}")	#其他需要链接的标志	  相当于执行: pkg-config opencv --libs-only-other
MESSAGE(STATUS "PKG_OPENCV_CFLAGS:         ${PKG_OPENCV_CFLAGS}")			#cflag可以指头文件    相当于执行: pkg-config opencv --cflags,多个,分开
MESSAGE(STATUS "PKG_OPENCV_CFLAGS_OTHER:   ${PKG_OPENCV_CFLAGS_OTHER}")		#其他cflag标志		 相当于执行: pkg-config opencv --libs-only-other


#将stereoVision.cpp编译成可执行文件
add_executable(stereoVision stereoVision.cpp)
# target_link_libraries(stereoVision ${OpenCV_LIBS} ${Pangolin_LIBRARIES})
#上面的${OpenCV_LIBS}不起作用,要用下面的${PKG_OPENCV_LIBRARIES},表示连接opencv4的lib库
target_link_libraries(stereoVision ${PKG_OPENCV_LIBRARIES} ${PKG_OPENCV_LDFLAGS} ${Pangolin_LIBRARIES})

然后执行

make build  && cd build
cmake ..
make 

你可能感兴趣的:(ubuntu20.04,opencv,opencv,计算机视觉,图像处理)