B
B
BlindShot962015-10-04 22:53:31
C++ / C#
BlindShot96, 2015-10-04 22:53:31

How to fix an error when compiling a project with OpenCv in Сlion?

I'm trying to connect the OpenCV library to a project in Clion. It seems that everything is connected, I registered the necessary in CMakeLists. But when compiling it gives errors:


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;
}

Tips from a similar issue on SO don't help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question