使用Cmake配置c ++ OpenCV项目 [英] Configuring an c++ OpenCV project with Cmake

查看:178
本文介绍了使用Cmake配置c ++ OpenCV项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这是创建使用OpenCV库的项目的基本步骤,因此您不需要手动包括所有的库。没有关于这个主题的详细信息,至少对于刚刚想要使用OpenCV的新手来说,可以这样:

I consider this a fundamental step for creating projects that use OpenCV libraries so you don't need to manually include all the libraries. There is not detailed information on this topic, at least for a newbie that just wants to use OpenCV as soon as posible, so:

这是最简单的可扩展的方式使用Cmake创建多平台c ++ OpenCV

推荐答案

包含两个子文件夹 src 包含的文件夹项目以及名为 CMakeLists.txt 的文件。

First: create a folder Project containing two subfolders src and include, and a file called CMakeLists.txt.

第二:将cpp放在src文件夹和头文件include文件夹中。

Second: Put your cpp inside the src folder and your headers in the include folders.

第三:您的CMakeLists.txt应如下所示:

Third: Your CMakeLists.txt should look like this:

cmake_minimum_required(VERSION 2.8) 
PROJECT (name)
find_package(OpenCV REQUIRED )
set( NAME_SRC
    src/main.cpp    
)

set( NAME_HEADERS       
     include/header.h
)

INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/include )
link_directories( ${CMAKE_BINARY_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
add_executable( name ${NAME_SRC} ${NAME_HEADERS} )

target_link_libraries( sample_pcTest ${OpenCV_LIBS} )

第四:打开CMake GUI并选择根文件夹作为输入,并为输出创建一个构建文件夹。单击配置,然后生成,并选择生成器(VisualStudio,Eclipse,...)

Fourth: Open CMake GUI and select the root folder as input and create a build folder for the output. Click configure, then generate, and choose the generator (VisualStudio, Eclipse, ...)

这篇关于使用Cmake配置c ++ OpenCV项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆