title: C++/CMake:Undefined reference to imwrite in OpenCV
body: <p>This is my CMakeLists.txt:</p>
  
  <pre><code>project(proj)
  set(OpenCV_DIR "/usr/lib/opencv")
  find_package(OpenCV REQUIRED COMPONENTS core imgproc highgui)
  
  include_directories(${OpenCV_INCLUDE_DIRS})
  add_executable(test test.cpp&gt;
  target_link_libraries(test ${OpenCV_LIBS})
  </code></pre>
  
  <p>and this is part of my code:</p>
  
  <pre><code>#include &lt;opencv/cv.h&gt;
  #include &lt;opencv/cv.hpp&gt;
  #include &lt;opencv/highgui.h&gt;
  #include &lt;opencv/highgui.hpp&gt;
  
  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);
  
      waitKey(0);                                          
      return 0;
  
  }
  </code></pre>
  
  <p>and the error message I get is:</p>
  
  <pre><code>undefined reference to cv::imwrite(std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, cv::Mat const&amp;, std::vector&lt;int, std::allocator&lt;int&gt; &gt; const&amp;)`
  </code></pre>
  
  <p>imshow works correctly, so I have no clue why imwrite is giving me an error.</p>
  
  <p>EDIT:</p>
  
  <pre><code>g++ -o test_1 test_1.cpp `pkg-config opencv --cflags --libs`
  </code></pre>
  
  <p>gives the same error.</p>