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

查看:36
本文介绍了使用 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 的最简单且可扩展的方法是什么?

推荐答案

首先:创建一个文件夹Project,其中包含两个子文件夹srcinclude,以及一个名为 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 并选择根文件夹作为输入并为输出创建一个构建文件夹.点击configure,然后generate,选择生成器(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天全站免登陆