I am trying to use g++ (from within Visual Studio 2019, Windows 10) to compile a .cpp file that imports OpenCV header files.
When g++ main.cpp didn't work, I searched here and found people recommending the use of -I to designate the path to the include files.
I have tried -I/path/to/opencv/include as a flag to my g++ command, but still receive the same error.
Would really appreciate it if someone could help me figure out why g++ is not finding the .hpp files...
Minimal code:
#include <iostream> #include <opencv2/core.hpp> int main() { return 0; } Error received:
No such file or directory 2 | #include <opencv2/core.hpp> | ^~~~~~~~~~~~~~~~ compilation terminated. Edit:
@KonradRudolph advised that I should not have a / between the -I flag and my include path. Replacing it with a space now yields a different error:
In file included from C:/Users/USER/OpenCV/opencv/build/include/opencv2/core.hpp:3307, from main.cpp:2: C:/Users/USER/OpenCV/opencv/build/include/opencv2/core/utility.hpp:717:14: error: 'recursive_mutex' in namespace 'std' does not name a type 717 | typedef std::recursive_mutex Mutex; | ^~~~~~~~~~~~~~~ C:/Users/USER/OpenCV/opencv/build/include/opencv2/core/utility.hpp:63:1: note: 'std::recursive_mutex' is defined in header <mutex>'; did you forget to '#include <mutex>'? 62 | #include <mutex> // std::mutex, std::lock_guard +++ |+#include <mutex> 63 | #endif C:/Users/USER/OpenCV/opencv/build/include/opencv2/core/utility.hpp:718:29: error: 'Mutex' is not a member of 'cv' 718 | typedef std::lock_guard<cv::Mutex> AutoLock; | ^~~~~ C:/Users/USER/OpenCV/opencv/build/include/opencv2/core/utility.hpp:718:29: error: 'Mutex' is not a member of 'cv' C:/Users/USER/OpenCV/opencv/build/include/opencv2/core/utility.hpp:718:34: error: template argument 1 is invalid 718 | typedef std::lock_guard<cv::Mutex> AutoLock; | ^
opencv2/core.hppmakes the compiler complain aboutopencv/core.hpp... ;) (well, not really, more likely you didn't check that your minimal code actually reproduces the problem)"opencv2/core.hpp"if it works\and/work. I don’t think g++ needs/between-Iand the path but I’m not a frequent user of mingw and it shouldn’t hurt.