0
votes

I tried to compile simple program using OpenCV 4.11 and current version of Mingw on Windows 7. I downloaded binaries for OpenCV from https://github.com/huihut/OpenCV-MinGW-Build. I tried to compile it using command: "g++ main.cpp -std=c++11 -I F:\cpp_tools\libs\OpenCV-MinGW-Build-OpenCV-4.1.1-x64\include -L F:\cpp_tools\libs\OpenCV-MinGW-Build-OpenCV-4.1.1-x64\x64\mingw\lib -lopencv_core411.dll -lopencv_imgcodecs411.dll -lopencv_imgproc411.dll -lopencv_highgui411.dll -o myprog.exe"

and i got linker error:
C:\Users\Radek\AppData\Local\Temp\ccyTSmo1.o:main.cpp:(.text+0xa0): undefined re ference to cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' C:\Users\Radek\AppData\Local\Temp\ccyTSmo1.o:main.cpp:(.text+0x13e): undefined r eference tocv::namedWindow(std::__cxx11::basic_string, std::allocator > const&, int)' C:\Users\Radek\AppData\Local\Temp\ccyTSmo1.o:main.cpp:(.text+0x19f): undefined r eference to cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)' C:\Users\Radek\AppData\Local\Temp\ccyTSmo1.o:main.cpp:(.text+0x1c9): undefined r eference tocv::waitKey(int)' C:\Users\Radek\AppData\Local\Temp\ccyTSmo1.o:main.cpp:(.text$_ZN2cv3MatD1Ev[__ZN 2cv3MatD1Ev]+0x2d): undefined reference to cv::fastFree(void*)' C:\Users\Radek\AppData\Local\Temp\ccyTSmo1.o:main.cpp:(.text$_ZN2cv3Mat7releaseE v[__ZN2cv3Mat7releaseEv]+0x40): undefined reference tocv::Mat::deallocate()' C:\Users\Radek\AppData\Local\Temp\ccyTSmo1.o:main.cpp:(.text$ZN2cv3MataSEOS0[_ ZN2cv3MataSEOS0]+0xb4): undefined reference to `cv::fastFree(void*)' collect2.exe: error: ld returned 1 exit status

I read alot of similar problems but any of it didn't solved my problem.

Source code:

#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <string>
using namespace cv;
using namespace std;

int main(int argc, char** argv) {
String imageName( "../data/HappyFish.jpg" ); // by default
if( argc > 1)
{
    imageName = argv[1];
}
Mat image;
image = imread( imageName, IMREAD_COLOR ); // Read the file
if( image.empty() )                      // Check for invalid input
{
    cout <<  "Could not open or find the image" << std::endl ;
    return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE ); 
imshow( "Display window", image );    
waitKey(0); // Wait for a keystroke in the window
return 0;
}
1

1 Answers

0
votes

Shouldn't it be

g++ main.cpp -std=c++11 -I F:\cpp_tools\libs\OpenCV-MinGW-    
Build-OpenCV-4.1.1-x64\include -L F:\cpp_tools\libs\OpenCV- 
MinGW-Build-OpenCV-4.1.1-x64\x64\mingw\lib  
-llibopencv_core411 -llibopencv_imgcodecs411  
-llibopencv_imgproc411 -llibopencv_highgui411 -o 
myprog.exe

with -llibopencv instead of -lopencv?

Have you tried the help Running a C++ program with OpenCV 3.4.1 using MinGW-w64 g++ in Visual Studio Code on Windows 10 x64 mentioned on GitHub?