Windows 10
Visual Studio Code
Compiler: C:msys64ucrt64bing++
When compiling the following code, I get no errors, and it prints out “Testing OpenCV version: 4.9.0” in the terminal as expected.
I use this to compile:
g++ -o out test.cpp -IC:opencvbuildinclude -LC:opencvbuildx64vc16lib -lopencv_world490
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main() {
//Mat image = imread("img.png");
cout << "Testing OpenCV version: " << CV_VERSION << endl;
return 0;
}
However, when I uncomment the Mat image and compile again using the same g++ command, I get this error:
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersadAppDataLocalTempcchH5PPc.o:test.cpp:(.text+0x4f): undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, int)’
I have added “C:opencvbuildx64vc16bin” and “C:opencvbuildx64vc16lib” to system variables path but not sure this relates to the problem.
Doing a bit of research, it seems for OpenCV 4, cv::imread is part of opencv_world library, so linking to other libraries like highgui or imgproc shouldn’t be necessarry, but I’m unsure about this too.
Any help greatly appriciated.