MinGW C++ compiler cant find OpenCV in the system path

Viewed 422

So I'm getting an error stating "fatal error: opencv2\core\mat.hpp: No such file or directory" when trying to compile a small c++ file from .cpp with MinGW. It happens in one form or another in Sublime Text 3, Atom, and on the command line with "gcc myfile.cpp". I should note that I'm on Windows 10. Here's the code:

#include <iostream>
#include <opencv2\core\mat.hpp>
#include <opencv2\core.hpp>
#include <opencv2\highgui.hpp>
#include <opencv2\core\types.hpp>
#include <opencv2\imgproc.hpp>

int main()
{
    std::cout << "Hello World!\n";
    cv::Mat img = cv::imread("despair.jpg");
    cv::cvtColor(img, img, cv::COLOR_RGBA2GRAY, 1);
    cv::imshow("1", img);
    cv::waitKey(0);

    cv::Mat mask = cv::Mat(img.rows, img.cols, CV_8UC1, cv::Scalar(255));
    cv::Rect_ <char> roi = cv::Rect_ <cv::Point>(cv::Point(0, 0), cv::Point(10, 10));
    cv::rectangle(mask, roi, cv::Scalar(0), -1);
    cv::Scalar colors = cv::mean(img, mask);
}

Things I've done and tried:

  • Adding C:\OpenCV\opencv\build\include\ to the system path.
  • Adding the bin and lib folders in x64/vc15 folder to the system path.
  • Messing and experimenting with the system path in general to try to find anything that might work. (I've tried so many combinations at this point I've forgotten most of them)
  • Adding everything to my user specific path.
  • Changing the include directory in the .cpp file to be the absolute path to each file I need to include (This works for the exact files I need, but then fails when those files try to include other files they need, like when Mat.hpp tries to include Matx.hpp)
  • Reinstalling MinGW64.
  • Installing MinGW to different folders and updating the system path to reflect the new location.
  • Changing which text editor I'm using
  • Compiling from the command line outside of a text editor

Things in my system path right now:

  • C:\OpenCV\opencv\build\x64\vc15\lib
  • C:\OpenCV\opencv\build\x64\vc15\bin
  • C:\OpenCV\opencv\build\include\
  • C:\MinGW\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin

I took this code out of a larger project to test what was going on with it and at this point I'm at my wits end trying to figure out what's wrong. Please send help.

1 Answers

Add -I option with path to opencv includes and -L with path to opencv libraries, like this:

gcc -IC:\OpenCV\opencv\build\include -LC:\OpenCV\opencv\build\x64\vc15\lib test_opencv.cpp
Related