Compiling an OpenCV project using CMake on Cygwin,

2019-08-10 20:01发布

Situation:

I have a Windows 7 machine with OpenCV for Windows installed on it. My OpenCV C++ projects work fine with Visual Studio 2010.

I want to run my existing OpenCV C++ projects to run on Raspberry Pi and on other Linux machines.

Trouble

As a first step, I am trying to compile my .cpp & .h files using GCC on Cygwin on my Windows Machine. For this purpose I am trying to use CMake package for Cygwin, but CMake gives error that it cannot find OpenCV package. (error is listed below).

Question:

  1. Do i need to install OpenCV package for Cygwin separately for CMake to work ?
  2. Is there a way to using my existing OpenCV for Win to work with CMake ?
  3. What environment variables need to be set ?
    (Currently only a variable OPENCV_DIR is set to C:/opencv/build)

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".

2条回答
可以哭但决不认输i
2楼-- · 2019-08-10 20:46

As @berak, stated in the comment, I installed OpenCV Package for Cygwin using Cygwin Ports. (Without any src or requiring any build, simple install only).
Had to tweak my CMakeLists.txt a little but it compiled well.

##### 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)

查看更多
时光不老,我们不散
3楼-- · 2019-08-10 20:55

The variable should be called OpenCV_DIR, it must have the same capitalization as in find_package(OpenCV REQUIRED).

查看更多
登录 后发表回答