Как исправить ошибку при компиляции проекта с OpenCv в Сlion?

Пытаюсь подключить библиотеку OpenCV к проекту в Clion. Вроде бы всё подключилось, прописал необходимое в CMakeLists. Но при компиляции пишет ошибки:

Linking CXX executable OpenCv_Test_1.exe
CMakeFiles\OpenCv_Test_1.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/Peter Zaydel/AndroidStudioProjects/OpenCv_Test_1/main.cpp:12: undefined reference to `cv::imread(cv::String const&, int)'
C:/Users/Peter Zaydel/AndroidStudioProjects/OpenCv_Test_1/main.cpp:20: undefined reference to `cv::namedWindow(cv::String const&, int)'
C:/Users/Peter Zaydel/AndroidStudioProjects/OpenCv_Test_1/main.cpp:21: undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
C:/Users/Peter Zaydel/AndroidStudioProjects/OpenCv_Test_1/main.cpp:23: undefined reference to `cv::waitKey(int)'
CMakeFiles\OpenCv_Test_1.dir/objects.a(main.cpp.obj): In function `ZN2cv6StringC1EPKc':
C:/OpenCV/opencv/build/include/opencv2/core/cvstd.hpp:618: undefined reference to `cv::String::allocate(unsigned int)'
CMakeFiles\OpenCv_Test_1.dir/objects.a(main.cpp.obj): In function `ZN2cv6StringD1Ev':
C:/OpenCV/opencv/build/include/opencv2/core/cvstd.hpp:660: undefined reference to `cv::String::deallocate()'
CMakeFiles\OpenCv_Test_1.dir/objects.a(main.cpp.obj): In function `ZN2cv3MatD1Ev':
C:/OpenCV/opencv/build/include/opencv2/core/mat.inl.hpp:556: undefined reference to `cv::fastFree(void*)'
CMakeFiles\OpenCv_Test_1.dir/objects.a(main.cpp.obj): In function `ZN2cv3MataSERKS0_':
C:/OpenCV/opencv/build/include/opencv2/core/mat.inl.hpp:577: undefined reference to `cv::Mat::copySize(cv::Mat const&)'
CMakeFiles\OpenCv_Test_1.dir/objects.a(main.cpp.obj): In function `ZN2cv3Mat7releaseEv':
C:/OpenCV/opencv/build/include/opencv2/core/mat.inl.hpp:667: undefined reference to `cv::Mat::deallocate()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [OpenCv_Test_1.exe] Error 1
CMakeFiles\OpenCv_Test_1.dir\build.make:87: recipe for target 'OpenCv_Test_1.exe' failed
CMakeFiles\Makefile2:59: recipe for target 'CMakeFiles/OpenCv_Test_1.dir/all' failed
mingw32-make.exe[2]: *** [CMakeFiles/OpenCv_Test_1.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/OpenCv_Test_1.dir/rule] Error 2
CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/OpenCv_Test_1.dir/rule' failed
Makefile:108: recipe for target 'OpenCv_Test_1' failed
mingw32-make.exe: *** [OpenCv_Test_1] Error 2


CMakeLists.txt :
cmake_minimum_required(VERSION 3.2)
project(OpenCv_Test_1)

include_directories(C:\\OpenCV\\opencv\\build\\include)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(OpenCV_DIR  "C:/OpenCV/opencv/build")
find_package(OpenCV REQUIRED )

IF(NOT OpenCV_FOUND)
    MESSAGE(FATAL_ERROR "OpenCV not found")
ENDIF()

set(SOURCE_FILES main.cpp)
add_executable(OpenCv_Test_1 ${SOURCE_FILES})
target_link_libraries( OpenCv_Test_1 ${OpenCV_LIBS} )<code></code>


main.cpp:
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
    cv::Mat image;
    image = cv::imread("C:/open_cv_image.jpg", CV_LOAD_IMAGE_COLOR);   // Read the file
    namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
    imshow( "Display window", image );                   // Show our image inside it.
    waitKey(0);                                          // Wait for a keystroke in the window
    return 0;
}


Советы из схожей проблемы на SO не помогают.
  • Вопрос задан
  • 2306 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы
CTRL+ Москва
от 250 000 до 320 000 ₽
CTRL+ Москва
от 200 000 до 300 000 ₽
CTRL+ Белград
от 250 000 до 320 000 ₽