Search code examples
c++opencvcmakeraspberry-piraspberry-pi4

${OpenCV_INCLUDE_DIRS} not set after building OpenCV from source


I followed this tutorial to build OpenCV: https://qengineering.eu/install-opencv-on-raspberry-pi.html

It built and installed successfully, but trying to include opencv2/opencv.hpp is not working. The file is definitely present in /usr/local/include/opencv4/opencv2/opencv.hpp.

I know I could just add it as an include directory in the C++ project with the -I flag, but I want to understand why it's not working.

The ${OpenCV_INCLUDE_DIRS} is not defined. Is it supposed to be added to .bashrc or somewhere else by Make? Did a certain step fail without warning?


Solution

  • Thanks to @drescherjm for pointing me to OpenCV make documentation and @Wutz for confirming:

    https://docs.opencv.org/4.x/db/df5/tutorial_linux_gcc_cmake.html

    This has you create CMakeLists.txt, then run cmake . to create Makefile, then run make to build using the makefile.

    That will correctly tell the compiler where OpenCV is using macros for include and lib.