I configured OpenCV 3.4.11 according to this post.
I am using MingGW as my compiler.
Here is what CMake GUI told me:
Detected processor: AMD64
sizeof(void) = 4 on 64 bit processor. Assume 32-bit compilation mode
libjpeg-turbo: VERSION = 2.0.5, BUILD = opencv-3.4.11-libjpeg-turbo
Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
Could NOT find BLAS (missing: BLAS_LIBRARIES)
LAPACK requires BLAS
A library with LAPACK API not found. Please specify library location.
Found apache ant: C:/apache-ant-1.10.8/bin/ant.bat (1.8.0)
Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
OpenCV Python: during development append to PYTHONPATH: D:/mingw-build-3.4.11/python_loader
Caffe: NO
Protobuf: NO
Glog: NO
freetype2: NO
harfbuzz: NO
Module opencv_ovis disabled because OGRE3D was not found
No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake.
Failed to find gflags - Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components.
Failed to find gflags - Could not find gflags include directory, set GFLAGS_INCLUDE_DIR to directory containing gflags/gflags.h
Failed to find glog - Could not find glog include directory, set GLOG_INCLUDE_DIR to directory containing glog/logging.h
Module opencv_sfm disabled because the following dependencies are not found: Eigen Glog/Gflags
Allocator metrics storage type: 'int'
Excluding from source files list: modules/imgproc/src/imgwarp.avx2.cpp
Excluding from source files list: modules/imgproc/src/resize.avx2.cpp
Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.avx2.cpp
Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.avx512_skx.cpp
Excluding from source files list: modules/features2d/src/fast.avx2.cpp
General configuration for OpenCV 3.4.11 =====================================
Version control: unknown
Extra modules:
Location (extra): D:/opencv_contrib-3.4.11/modules
Version control (extra): unknown
Platform:
Timestamp: 2020-08-15T06:52:46Z
Host: Windows 10.0.18363 AMD64
CMake: 3.18.1
CMake generator: MinGW Makefiles
CMake build tool: C:/MinGW/bin/mingw32-make.exe
Configuration: Release
CPU/HW features:
Baseline: SSE SSE2
requested: SSE2
Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX
requested: SSE4_1 SSE4_2 AVX FP16
SSE4_1 (14 files): + SSE3 SSSE3 SSE4_1
SSE4_2 (1 files): + SSE3 SSSE3 SSE4_1 POPCNT SSE4_2
FP16 (0 files): + SSE3 SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
AVX (5 files): + SSE3 SSSE3 SSE4_1 POPCNT SSE4_2 AVX
C/C++:
Built as dynamic libs?: NO
C++11: YES
C++ Compiler: C:/Strawberry/c/bin/g++.exe (ver 4.9.2)
C++ flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-comment -Wno-missing-field-initializers -fdiagnostics-show-option -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -mfpmath=sse -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
C++ flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-comment -Wno-missing-field-initializers -fdiagnostics-show-option -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -mfpmath=sse -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
C Compiler: C:/Strawberry/c/bin/gcc.exe
C flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wno-missing-field-initializers -fdiagnostics-show-option -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -mfpmath=sse -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG
C flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wno-missing-field-initializers -fdiagnostics-show-option -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -mfpmath=sse -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG
Linker flags (Release): -Wl,--gc-sections
Linker flags (Debug): -Wl,--gc-sections
ccache: NO
Precompiled headers: NO
Extra dependencies: comctl32 gdi32 ole32 setupapi ws2_32 winmm
3rdparty dependencies: libprotobuf zlib libjpeg-turbo libwebp libpng libtiff libjasper IlmImf quirc
OpenCV modules:
To be built: aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dpm face features2d flann fuzzy hfs highgui img_hash imgcodecs imgproc line_descriptor ml objdetect optflow phase_unwrapping photo plot reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
Disabled: python_bindings_generator python_tests world
Disabled by dependency: -
Unavailable: cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv freetype hdf java js matlab ovis python2 python3 sfm viz
Applications: apps
Documentation: NO
Non-free algorithms: NO
Windows RT support: NO
GUI:
Win32 UI: YES
VTK support: NO
Media I/O:
ZLib: build (ver 1.2.11)
JPEG: build-libjpeg-turbo (ver 2.0.5-62)
WEBP: build (ver encoder: 0x020f)
PNG: build (ver 1.6.37)
TIFF: build (ver 42 - 4.0.10)
JPEG 2000: build (ver 1.900.1)
OpenEXR: build (ver 2.3.0)
HDR: YES
SUNRASTER: YES
PXM: YES
Video I/O:
DC1394: NO
FFMPEG: YES (prebuilt binaries)
avcodec: YES (ver 57.107.100)
avformat: YES (ver 57.83.100)
avutil: YES (ver 55.78.100)
swscale: YES (ver 4.8.100)
avresample: YES (ver 3.7.0)
GStreamer: NO
DirectShow: YES
Parallel framework: none
Trace: YES (built-in)
Other third-party libraries:
Lapack: NO
Eigen: NO
Custom HAL: NO
Protobuf: build (3.5.1)
OpenCL: YES (no extra features)
Include path: D:/opencv-3.4.11/sources/3rdparty/include/opencl/1.2
Link libraries: Dynamic load
Python (for build): C:/Users/Administrator/AppData/Local/Programs/Python/Python38-32/python.exe
Java:
ant: C:/apache-ant-1.10.8/bin/ant.bat (ver 1.8.0)
JNI: NO
Java wrappers: NO
Java tests: NO
Install to: D:/mingw-build-3.4.11/install
-----------------------------------------------------------------
Configuring done
After applying mingw32-make -j8
and mingw32-make install
in CMD, it built successfully.
Then, I add D:\mingw-build-3.4.11\install\x64\mingw\bin
to my System PATH and restarted my computer.
The step 10 tells me to download FindOpenCV.cmake and add it to project-root/cmake/. However, this link responsed 502 Bad Gateway, thus I jumped over this step.
The following is my project contents:
CMakeLists.txt
cmake_minimum_required(VERSION 3.6)
project(opencv)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
# Where to find CMake modules and OpenCV
set(OpenCV_DIR "D:\\mingw-build-3.4.11\\install")
find_package(OpenCV REQUIRED core highgui imgproc imgcodecs)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(opencv opencv.cpp)
# add libs you need
set(OpenCV_LIBS opencv_core opencv_imgproc opencv_highgui opencv_imgcodecs)
# linking
target_link_libraries(opencv ${OpenCV_LIBS})
opencv.cpp
#include <opencv2/opencv.hpp>
using namespace cv;
int main() {
Mat mat = imread("1.jpg");
imshow("1", mat);
}
CMake build successfully like following:
"D:\Program Files\JetBrains\CLion 2020.1.2\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" D:\Users\Administrator\Documents\Codes\CLionProjects\opencv
-- OpenCV ARCH: x64
-- OpenCV RUNTIME: mingw
-- OpenCV STATIC: OFF
-- Found OpenCV 3.4.11 in D:/mingw-build-3.4.11/install/x64/mingw/lib
-- You might need to add D:/mingw-build-3.4.11/install/x64/mingw/bin to your PATH to be able to run your applications.
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Users/Administrator/Documents/Codes/CLionProjects/opencv/cmake-build-debug
[Finished]
However, everytime I run this application, compiler keeps telling me:
====================[ Build | opencv | Debug ]==================================
"D:\Program Files\JetBrains\CLion 2020.1.2\bin\cmake\win\bin\cmake.exe" --build D:\Users\Administrator\Documents\Codes\CLionProjects\opencv\cmake-build-debug --target opencv -- -j 4
[ 50%] Linking CXX executable opencv.exe
CMakeFiles\opencv.dir/objects.a(opencv.cpp.obj): In function `main':
D:/Users/Administrator/Documents/Codes/CLionProjects/opencv/opencv.cpp:6: undefined reference to `cv::imread(cv::String const&, int)'
D:/Users/Administrator/Documents/Codes/CLionProjects/opencv/opencv.cpp:7: undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
CMakeFiles\opencv.dir/objects.a(opencv.cpp.obj): In function `cv::String::String(char const*)':
D:/mingw-build-3.4.11/install/include/opencv2/core/cvstd.hpp:602: undefined reference to `cv::String::allocate(unsigned long long)'
CMakeFiles\opencv.dir/objects.a(opencv.cpp.obj): In function `cv::String::~String()':
D:/mingw-build-3.4.11/install/include/opencv2/core/cvstd.hpp:648: undefined reference to `cv::String::deallocate()'
CMakeFiles\opencv.dir/objects.a(opencv.cpp.obj): In function `cv::String::operator=(cv::String const&)':
D:/mingw-build-3.4.11/install/include/opencv2/core/cvstd.hpp:656: undefined reference to `cv::String::deallocate()'
CMakeFiles\opencv.dir/objects.a(opencv.cpp.obj): In function `cv::Mat::~Mat()':
D:/mingw-build-3.4.11/install/include/opencv2/core/mat.inl.hpp:786: undefined reference to `cv::fastFree(void*)'
CMakeFiles\opencv.dir/objects.a(opencv.cpp.obj): In function `cv::Mat::release()':
D:/mingw-build-3.4.11/install/include/opencv2/core/mat.inl.hpp:898: undefined reference to `cv::Mat::deallocate()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\opencv.dir\build.make:91: opencv.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:75: CMakeFiles/opencv.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:82: CMakeFiles/opencv.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: opencv] Error 2
Actually no error founded in code check. Moreover, I can find the imread
source code through click function with CTRL button pressed.