huihut / OpenCV-MinGW-Build

👀 MinGW 32bit and 64bit version of OpenCV compiled on Windows. Including OpenCV 3.3.1, 3.4.1, 3.4.1-x64, 3.4.5, 3.4.6, 3.4.7, 3.4.8-x64, 3.4.9, 4.0.0-alpha-x64, 4.0.0-rc-x64, 4.0.1-x64, 4.1.0, 4.1.0-x64, 4.1.1-x64, 4.5.0-with-contrib, 4.5.2-x64
https://opencv.org/
928 stars 215 forks source link

error on vs code #2

Closed ghost closed 5 years ago

ghost commented 5 years ago

I am completely noob on c++

I have cloned your repo x64 version

And when I run this command I get the error.

Command

g++ ./src/main.cpp -I C:/OpenCV-MinGW-Build-OpenCV-3.4.1-x64/include -L C:/OpenCV-MinGW-Build-OpenCV-3.4.1-x64/x64/mingw/lib -llibopencv_core341 -llibopencv_highgui341 -o app

Error

> Executing task:  g++ ./src/main.cpp -I C:/OpenCV-MinGW-Build-OpenCV-3.4.1-x64/include -L C:/OpenCV-MinGW-Build-OpenCV-3.4.1-x64/x64/mingw/lib -llibopencv_core341 -llibopencv_highgui341 -o app <

C:\Users\giorg\AppData\Local\Temp\ccVLePpF.o:main.cpp:(.text+0x51): undefined reference to `cv::imread(cv::String const&, int)'
C:\Users\giorg\AppData\Local\Temp\ccVLePpF.o:main.cpp:(.text+0xa2): undefined reference to `cv::namedWindow(cv::String const&, int)'
C:\Users\giorg\AppData\Local\Temp\ccVLePpF.o:main.cpp:(.text+0x119): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
C:\Users\giorg\AppData\Local\Temp\ccVLePpF.o:main.cpp:(.text+0x139): undefined reference to `cv::waitKey(int)'
C:\Users\giorg\AppData\Local\Temp\ccVLePpF.o:main.cpp:(.text$_ZN2cv6StringC1EPKc[__ZN2cv6StringC1EPKc]+0x42): undefined reference to `cv::String::allocate(unsigned int)'
C:\Users\giorg\AppData\Local\Temp\ccVLePpF.o:main.cpp:(.text$_ZN2cv6StringD1Ev[__ZN2cv6StringD1Ev]+0xf): undefined reference to `cv::String::deallocate()'
C:\Users\giorg\AppData\Local\Temp\ccVLePpF.o:main.cpp:(.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]+0x2d): undefined reference to `cv::fastFree(void*)'
C:\Users\giorg\AppData\Local\Temp\ccVLePpF.o:main.cpp:(.text$_ZN2cv3Mat7releaseEv[__ZN2cv3Mat7releaseEv]+0x40): undefined reference to `cv::Mat::deallocate()'
C:\Users\giorg\AppData\Local\Temp\ccVLePpF.o:main.cpp:(.text$_ZN2cv3MataSEOS0_[__ZN2cv3MataSEOS0_]+0xb4): undefined reference to `cv::fastFree(void*)'
collect2.exe: error: ld returned 1 exit status
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.
ghost commented 5 years ago

I have previously made a StackOverflow question more on this here https://stackoverflow.com/questions/51622111/opencv-c-mingw-vscode-fatal-error-to-compile?noredirect=1#comment90210559_51622111

huihut commented 5 years ago

This is the ld linker can't find cv.

g++ ./src/main.cpp -I C:/OpenCV-MinGW-Build-OpenCV-3.4.1-x64/include -L C:/OpenCV-MinGW-Build-OpenCV-3.4.1-x64/x64/mingw/bin -llibopencv_core341 -llibopencv_highgui341 -llibopencv_imgcodecs341 -o app

(see OpenCV : undefined reference to imread()) Can this work?

reg31 commented 5 years ago

Answer:

https://stackoverflow.com/questions/43786856/how-can-i-install-configure-opencv3-2-0-with-c-visual-studio-2017

MinGW libs from this repo are to be used with QT, so this will not work as they target a different compiler.

For Visual studio, I advise you to compile your own libraries following the link above.

agtbaskara commented 5 years ago

I manage to use the MinGW build OpenCV with g++ and Visual Studio Code https://stackoverflow.com/a/51801863