C++/CMake:Undefined reference to imwrite in OpenCV

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

C++/CMake:Undefined reference to imwrite in OpenCV

This post has NOT been accepted by the mailing list yet.
This is my CMakeLists.txt:

set(OpenCV_DIR "/usr/lib/opencv")
find_package(OpenCV REQUIRED COMPONENTS core imgproc highgui)

add_executable(test test.cpp>
target_link_libraries(test ${OpenCV_LIBS})
and this is part of my code:

#include <opencv/cv.h>
#include <opencv/cv.hpp>
#include <opencv/highgui.h>
#include <opencv/highgui.hpp>

using namespace cv;
using namespace std;

int main(int argv, char **argc)
    //other code
    Mat img(height, width, CV_8UC3);
    //other code

    imwrite("/path", img);
    namedWindow( "Display window", 1 );
    imshow("Display window", img);

    return 0;

and the error message I get is:  undefined reference to cv::imwrite(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::Mat const&, std::vector<int, std::allocator<int> > const&)

imshow works correctly, so I have no clue why imwrite is giving me an error.