[英]Compiling an OpenCV project using CMake on Cygwin, with OpenCV installed for Windows
I have a Windows 7 machine with OpenCV for Windows installed on it.我有一台装有OpenCV for Windows的 Windows 7 机器。 My OpenCV C++ projects work fine with Visual Studio 2010.
我的 OpenCV C++ 项目在 Visual Studio 2010 中运行良好。
I want to run my existing OpenCV C++ projects to run on Raspberry Pi and on other Linux machines.我想运行我现有的 OpenCV C++ 项目以在 Raspberry Pi 和其他 Linux 机器上运行。
As a first step, I am trying to compile my .cpp & .h files using GCC on Cygwin on my Windows Machine.作为第一步,我尝试在 Windows 机器上的Cygwin上使用GCC编译我的 .cpp 和 .h 文件。 For this purpose I am trying to use CMake package for Cygwin , but CMake gives error that it cannot find OpenCV package.
为此,我尝试将CMake 包用于 Cygwin ,但CMake给出了找不到 OpenCV 包的错误。 (error is listed below).
(错误在下面列出)。
CMakeLists.txt CMakeLists.txt
cmake_minimum_required(VERSION 2.8.4)
PROJECT (testProj)
find_package(OpenCV REQUIRED )
set( NAME_SRC
src/main.cpp
src/imgProcess.cpp
)
set( NAME_HEADERS
include/imgProcess.h
)
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/include )
link_directories( ${CMAKE_BINARY_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
add_executable( testProj ${NAME_SRC} ${NAME_HEADERS} )
target_link_libraries( test ${OpenCV_LIBS} )
cmake error错误
$ cmake .
-- The C compiler identification is GNU 4.9.3
-- The CXX compiler identification is GNU 4.9.3
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++.exe
-- Check for working CXX compiler: /usr/bin/c++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:3 (find_package):
By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OpenCV", but
CMake did not find one.
Could not find a package configuration file provided by "OpenCV" with any
of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/cygdrive/c/Work/Project/cmaketest/CMakeFiles/CMakeOutput.log".
该变量应称为OpenCV_DIR
,它必须与find_package(OpenCV REQUIRED)
中的find_package(OpenCV REQUIRED)
相同。
As @berak, stated in the comment, I installed OpenCV Package for Cygwin using Cygwin Ports.正如@berak 在评论中所述,我使用 Cygwin Ports 为 Cygwin 安装了 OpenCV 包。 (Without any src or requiring any build, simple install only).
(没有任何 src 或需要任何构建,仅简单安装)。
Had to tweak my CMakeLists.txt
a little but it compiled well.不得不稍微调整我的
CMakeLists.txt
但它编译得很好。
##### CMakeLists.txt ########
cmake_minimum_required(VERSION 2.8.4)
PROJECT (test)
find_package(OpenCV REQUIRED )
set( NAME_SRC
src/main.cpp
src/mytest.cpp
)
set( NAME_HEADERS
include/mytest.hpp
)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
add_executable( test ${NAME_SRC} ${NAME_HEADERS} )
include_directories(/usr/include /usr/include/opencv2 /usr/include/opencv ${CMAKE_CURRENT_SOURCE_DIR}/include)
link_directories(/usr/lib ${CMAKE_BINARY_DIR}/bin)
target_link_libraries(test opencv_core opencv_highgui opencv_imgproc)
(Now, I have totally different trouble of runtime error : Gtk-WARNING **: cannot open display
, but its another story of not having XServer on Cygwin) (现在,我遇到了完全不同的运行时错误问题:
Gtk-WARNING **: cannot open display
,但这是另一个关于 Cygwin 上没有 XServer 的故事)
First take the following steps to build opencv using visual studio and cmake gui.首先按照以下步骤使用visual studio和cmake gui构建opencv。
$ git clone https://github.com/Itseez/opencv.git
$ git checkout 3.0.0
Create a build directory and build opencv in there using CMake and visual studio.创建一个构建目录并使用 CMake 和 Visual Studio 在其中构建 opencv。 Note that by default opencv will build dynamic libraries unless you enable the option of building opencv static libraries.
请注意,默认情况下 opencv 将构建动态库,除非您启用构建 opencv 静态库的选项。
Once done you should handle the environment variables.完成后,您应该处理环境变量。 Create a variable named OpenCV_DIR and point it to the build directory of opencv.
创建一个名为 OpenCV_DIR 的变量并将其指向 opencv 的构建目录。 Then update your PATH variable to have new opencv
dll
files added.然后更新您的 PATH 变量以添加新的 opencv
dll
文件。 Usually they can be found in the directory opencv\\build\\bin\\Release
assuming you have built opencv in Release
mode通常它们可以在目录
opencv\\build\\bin\\Release
假设您已经在Release
模式下构建了 opencv
Then set up your project CMakeList.txt
as follows然后如下设置你的项目
CMakeList.txt
find_package(OpenCV REQUIRED)
include_directories(
${OpenCV_INCLUDE_DIRS}
)
target_link_libraries(test
${OpenCV_LIBS}
)
The command find_package(OpenCV REQUIRED)
finds the opencv configuration files in the directory "opencv/build", aka the directory in which you have built opencv (That's why you should set the value of the variable ${OpenCV_DIR}
to this directory so the command find_package
can find the required files in there).命令
find_package(OpenCV REQUIRED)
在目录“opencv/build”中找到 opencv 配置文件,也就是你构建 opencv 的目录(这就是为什么你应该将变量${OpenCV_DIR}
的值设置到这个目录,以便命令find_package
可以在那里找到所需的文件)。
The two variables {OpenCV_INCLUDE_DIRS}
and ${OpenCV_LIBS}
have already been set in those configuration files.已经在这些配置文件中设置了两个变量
{OpenCV_INCLUDE_DIRS}
和${OpenCV_LIBS}
。 So you should be all set.所以你应该准备好了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.