Opencv doesnt work, it prints error

Hello, i included opencv in a program:
#include
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main() {
cout << “Hello”;
}
and it is always prints error like: error: ‘recursive_mutex’ in namespace ‘std’ does not name a type (typedef std::recursive_mutex Mutex;)
and: error: ‘Mutex’ is not a member of ‘cv’ (typedef std::lock_guardcv::Mutex AutoLock;)
Can somebody help?

os ? opencv version ? compiler ?

crosspost: c++ - Opencv, many errors like ... in namespace 'cv' does not name a type - Stack Overflow

windows 10, 4.6.0 (i tried with other versions, always prints error), g++ (MinGW.org GCC-6.3.0-1) 6.3.0

try to get a more recent mingw. this one works:


C:\Users\admin>g++ --version
g++ (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0

Also, is OpenCV built for MingW, or the standard version, which is for Visual C++? If not, it should not work…

thanks you so much guys!

the prebuild binaries are indeed for VS only.
(problem above happened when building from src)

Thank you, the including is working, but if i compile this code:

#include <bits/stdc++.h>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
using namespace std;
int main() {
    cv::Mat image;
    return 0;
}

like: g++ main.cpp
then it will print an error:

c:/winlibs/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.1/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\TAKCSN~1\AppData\Local\Temp\ccKc8Dmu.o:g.cpp:(.text+0x1e): undefined reference to `cv::Mat::Mat()'
c:/winlibs/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.1/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\TAKCSN~1\AppData\Local\Temp\ccKc8Dmu.o:g.cpp:(.text+0x2f): undefined reference to `cv::Mat::~Mat()'

collect2.exe: error: ld returned 1 exit status
Can you help?

you additionally need to link your program against the opencv libs:

g++ main.cpp -lopencv_core460 -lopencv_highgui460

Hi, i want to ask how can i link it, should i give the path?

-L path/to/your/lib/folder

Thank you very much, you helped me a lot!

Hi, unfortunately it does not work.
I have this code:
#include <bits/stdc++.h>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
using namespace std;
int main() {
cv::Mat image;
return 0;
}

and I tried a lot of options to link the library, but it returns error.
I tried to use these paths:
g++ main.cpp -L C:/opencv/build/include/opencv2/
g++ main.cpp -L C:\opencv\build\include\opencv2\highgui\

and the error remained the same: undefined reference to `cv::Mat::Mat()’
Can you help?
Because i would like to solve this program very much.
It’s a challange for me.

-L needs path to the installed libs, not the headers