0
votes

I'm trying to compile a project with CMAKE and make with MinGW32-make.exe. My CMakeLists.txt looks like so:

#####################################
cmake_minimum_required (VERSION 3.0) 
project (TestProject)
find_package(OpenCV REQUIRED)
include_directories(${OPENCV_INCLUDE_DIR})
add_executable (main.exe main.cpp)
#####################################

Running "CMAKE -G "MinGW Makefiles" runs fine, but when I try to make with "MinGW32-make.exe" I get the following error:

25:39: fatal error: opencv2/highgui/highgui.hpp: No such file or directory
 #include "opencv2/highgui/highgui.hpp"

When I look in the Makefile, I can't find the text "OpenCV" anywhere. In which file is the OPENCV directory supposed to be identified?

1
It is OpenCV_INCLUDE_DIRS variable which contains directory with OpenCV headers. You should use it instead of OPENCV_INCLUDE_DIR for include_directories() call. You may output content of variable using message() command. Note, that directory path needn't to contain OpenCV substring.Tsyvarev
I followed your advice and used the line: "message(STATUS "OPENCV DIRECTORY: " ${OpenCV_INCLUDE_DIRS}) and it returned an empty value, same for _DIR. When it finds the package shouldn't it set this variable?DrTarr
I took a second look, capitalization is what tripped me up. It now successfully links the OpenCV directory, thank you! Now every function i'm using from OpenCV gives an 'undefined reference' error. I suppose I have to use "target_link_libraries" for each individual dynamic library I'm using?DrTarr

1 Answers

2
votes

You are not arrive to link libraries, the system doesn't find the opencv headers this is because your include directories are no correctly set.

It is very important to specify where is your OpenCV build directory which is located your OpencvConfig.cmake file.

Besides you need to link your libraries with target_link_libraries.

So in conclusion your cmake code should be something like this:

cmake_minimum_required (VERSION 3.0) 
project( TestProject )
find_package( OpenCV REQUIRED )
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable( main main.cpp )
target_link_libraries( main ${OpenCV_LIBS} )