Using OpenCV with QT 6 and CMake
-
First of all thank you for your quick reply. As you can see below I have already linked libraries.
target_link_libraries(QT2 ${OpenCV_LIBS} Qt${QT_VERSION_MAJOR}::Core)
OpenCV_LIBS variable contains libraries below;
-- version: 4.5.5
-- libraries: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_gapi;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_stitching;opencv_video;opencv_videoio;opencv_world -
Hi and welcome to devnet,
Did you try the example shown here ?
It's for Linux however the code and cmake file should work all the same on Windows.
-
Hi, my cmake configuration is almost same. You can check it below.
cmake_minimum_required(VERSION 3.14)
project(QT2 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
find_package(OpenCV REQUIRED)
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable(QT2
main.cpp
)target_link_libraries(QT2 ${OpenCV_LIBS} Qt${QT_VERSION_MAJOR}::Core)
I still get same error.
:-1: error: CMakeFiles/QT2.dir/main.cpp.obj:C:/Users/ozgurA/Documents/QT/QT2/main.cpp:11: undefined reference to `cv::Mat::Mat()'
-
How did you install OpenCV ?
-
I have downloaded OpenCV 4.5.5 from the link https://opencv.org/releases/
then extracted into c:\opencv folder. After then set C:\OpenCV\build\x64\vc15\bin and C:\OpenCV\build\x64\vc15\lib folders into Path variable in Environment variables. -
Can you check with the previous version to see if the same is happening ?
-
As suggested before, try building your application without Qt in it to ensure that your OpenCV installation is working.
-
This worked for me for the Qt+OpenCV+Windows combo. Extracted the OpenCV windows binary release into C:\Qt\opencv
CMake for opencv includes and libraries
set(OpenCV_DIR "C:/Qt/opencv/build") find_package(OpenCV REQUIRED) include_directories( ${OpenCV_INCLUDE_DIRS} ) add_executable(qtopencv main.cpp ) target_link_libraries(qtopencv Qt${QT_VERSION_MAJOR}::Core ${OpenCV_LIBS})