0
votes

I am trying to build simple program in VSCode that uses OpenCV, read thousands of posts on stack already and they all are made on linux (and I try to do it on windows) here's my code

This is what i tried to use:

"args": [
                "-g",
                "-I",
                "C:\\OpenCV\\opencv\\build\\include",
                "${file}",
                "-L",
                "C:\\OpenCV\\opencv\\build\\x64\\vc15\\lib",
                "-l",
                "opencv_world345",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],

I checked the paths few times

#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
    if ( argc != 2 )
    {
        printf("usage: DisplayImage.out <Image_Path>\n");
        return -1;
    }
    Mat image;
    image = imread( argv[1], 1 );
    if ( !image.data )
    {
        printf("No image data \n");
        return -1;
    }
    namedWindow("Display Image", WINDOW_AUTOSIZE );
    imshow("Display Image", image);
    waitKey(0);
    return 0;
}

And this is the result i got

Executing task: C:\MinGW\bin\g++.exe -I C:\OpenCV\opencv\build\include >d:\programowanie\Projekt\Project\main.cpp -L >C:\OpenCV\opencv\build\x64\vc15\lib -l opencv_world345 -o >d:\programowanie\Projekt\Project\main.exe <

c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: >C:\Users\xxx\AppData\Local\Temp\ccXtHNOY.o:main.cpp:(.text+0x72):undefined reference to cv::imread(cv::String const&, int)' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: >C:\Users\xxx\AppData\Local\Temp\ccXtHNOY.o:main.cpp:(.text+0xe3): undefined reference tocv::namedWindow(cv::String const&, int)' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: >C:\Users\xxx\AppData\Local\Temp\ccXtHNOY.o:main.cpp:(.text+0x129): >undefined reference to cv::imshow(cv::String const&, cv::_InputArray const&)' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: >C:\Users\xxx\AppData\Local\Temp\ccXtHNOY.o:main.cpp:(.text+0x149): >undefined reference tocv::waitKey(int)' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: >C:\Users\xxx\AppData\Local\Temp\ccXtHNOY.o:main.cpp:(.text$_ZN2cv6StringC1EPKc[__ZN2cv6StringC1EPKc]+0x42): undefined reference to cv::String::allocate(unsigned int)' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: >C:\Users\xxx\AppData\Local\Temp\ccXtHNOY.o:main.cpp:(.text$_ZN2cv6StringD1Ev[__ZN2cv6StringD1Ev]+0xf): undefined reference tocv::String::deallocate()' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: >C:\Users\xxx\AppData\Local\Temp\ccXtHNOY.o:main.cpp:(.text$ZN2cv6StringaSERKS0[__ZN2cv6StringaSERKS0_]+0x1c): undefined reference to cv::String::deallocate()' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: >C:\Users\xxx\AppData\Local\Temp\ccXtHNOY.o:main.cpp:(.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]+0x2d): undefined reference tocv::fastFree(void*)'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: >C:\Users\xxx\AppData\Local\Temp\ccXtHNOY.o:main.cpp:(.text$_ZN2cv3Mat7releaseEv[__ZN2cv3Mat7releaseEv]+0x40): undefined reference to cv::Mat::deallocate()' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: >C:\Users\xxx\AppData\Local\Temp\ccXtHNOY.o:main.cpp:(.text$_ZN2cv3MataSEOS0_[__ZN2cv3MataSEOS0_]+0xb4): undefined reference tocv::fastFree(void*)' collect2.exe: error: ld returned 1 exit status

Im losing my senses and hope that anyone got idea what's going on

1
"C:\\OpenCV\\opencv\\build\\x64\\vc15\\lib", is no good for gcc/mingw. Those are Visual Studio binaries.drescherjm
hmm that could be the root of a problem, how can i get valid libs? Im bad in lib stuff :(Bkjvk
A quick google search shows this link looking promising: https://github.com/huihut/OpenCV-MinGW-Builddrescherjm

1 Answers

3
votes

The problem is you are using Visual Studio binaries for mingw. This may work if the library is a c library but will not work for opencv. The following site has unofficial opencv binaries for mingw: https://github.com/huihut/OpenCV-MinGW-Build