How to correctly link opencv library to clion?

  c++, opencv

I need help with linking opencv library to my clion project. I am trying to do this on Windows 10. I’ve tried to do following steps:
– Install OpenCV from opencv.org in verssion 4.5.1
– Add C:OpenCV_4.5.1buildx64vc15bin to system PATH variable
– Add lines to CMakeLists.txt:

cmake_minimum_required(VERSION 3.17)
project(opencv)

set(CMAKE_CXX_STANDARD 17)

add_executable(opencv main.cpp)

set(OpenCV_DIR "C:OpenCV_4.5.1buildx64vc15lib")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(opencv ${OpenCV_LIBS})

But the library still doesn’t work. After compiling I’m getting these errors:

undefined reference to `cv::Mat::Mat()'
undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
undefined reference to `cv::waitKey(int)'
undefined reference to `cv::Mat::~Mat()'
undefined reference to `cv::VideoCapture::~VideoCapture()'
undefined reference to `cv::Mat::~Mat()'

I don’t know how to solve this, I will be verry greatful for helping me. Thanks in advance.

Source: Windows Questions C++

LEAVE A COMMENT