title: OpenCV: undefined reference to `cv::namedWindow(cv::String const&, int)'
body: <p>UPDATE: The code compiles successfully on another computer. So the problem is not with the code itself but with the way I have the dependencies installed.</p>
  
  <hr>
  
  <p>If I have omitted any necessary information, please let me know. The full code can be found <a href="https://github.com/chicagoedt/revo_robot/tree/development/lane_finding" rel="nofollow noreferrer">here</a>.</p>
  
  <p>The following code compiles and runs perfectly fine on Ubuntu 14.04 with OpenCV 3.2.0 freshly installed from SourceForge using <a href="http://docs.opencv.org/3.0-beta/doc/tutorials/introduction/linux_install/linux_install.html" rel="nofollow noreferrer">these instructions</a>:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;opencv2/opencv.hpp&gt;
  
  using namespace cv;
  
  int main(int argc, char** argv )
  {
      Mat image;
      image = imread( argv[1], 1 );
      namedWindow("Display Image", WINDOW_AUTOSIZE );
      imshow("Display Image", image);
      waitkey(0);
  
      return 0;
  }
  </code></pre>
  
  <p>Using the following CMakeLists.txt:</p>
  
  <pre><code> cmake_minimum_required(VERSION 2.8)
   project( DisplayImage )
   find_package( OpenCV REQUIRED )
   add_executable( DisplayImage DisplayImage.cpp )
   target_link_libraries( DisplayImage ${OpenCV_LIBS} )
  </code></pre>
  
  <p>The following code fails to compile.</p>
  
  <p>lane_finder.h</p>
  
  <pre><code>#ifndef Lane_Finder_h
  #define Lane_Finder_h
  
  #include &lt;stdio.h&gt;
  #include &lt;ros/ros.h&gt;
  #include &lt;sensor_msgs/Image.h&gt;
  #include &lt;sensor_msgs/image_encodings.h&gt;
  #include &lt;cv_bridge/cv_bridge.h&gt;
  #include &lt;opencv2/opencv.hpp&gt;
  
  class LaneFinder
  { *snip* }
  
  #endif
  </code></pre>
  
  <p>lane_finder.cpp:</p>
  
  <pre><code>#include "lane_finder.h"
  
  sensor_msgs::CompressedImage LaneFinder::findLanes(const sensor_msgs::Image&amp; msg) {
      *snip*
      frame = in_msg-&gt;image;
  
      cv::namedWindow("Display Image", cv::WINDOW_AUTOSIZE );
      cv::imshow("Display Image", frame);
      *snip*
  }
  </code></pre>
  
  <p>CMakeLists.txt:</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.8.3)
  project(lane_finding)
  find_package(catkin REQUIRED COMPONENTS roscpp cv_bridge sensor_msgs)
  find_package(OpenCV REQUIRED)
  catkin_package()
  include_directories(include ${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
  add_executable(lane_finder src/lane_finder.cpp src/main.cpp)
  target_link_libraries(lane_finder
     ${catkin_LIBRARIES}
     ${OpenCV_LIBS}
  )
  </code></pre>
  
  <p>Compile Errors:</p>
  
  <pre><code>CMakeFiles/lane_finder.dir/src/lane_finder.cpp.o: In function `LaneFinder::findLanes(sensor_msgs::Image_&lt;std::allocator&lt;void&gt; &gt; const&amp;)':
  lane_finder.cpp:(.text+0x36c): undefined reference to `cv::namedWindow(cv::String const&amp;, int)'
  lane_finder.cpp:(.text+0x3c1): undefined reference to `cv::imshow(cv::String const&amp;, cv::_InputArray const&amp;)'
  CMakeFiles/lane_finder.dir/src/lane_finder.cpp.o: In function `cv::String::String(char const*)':
  lane_finder.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4f): undefined reference to `cv::String::allocate(unsigned long)'
  CMakeFiles/lane_finder.dir/src/lane_finder.cpp.o: In function `cv::String::~String()':
  lane_finder.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
  CMakeFiles/lane_finder.dir/src/lane_finder.cpp.o: In function `cv::String::operator=(cv::String const&amp;)':
  lane_finder.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x28): undefined reference to `cv::String::deallocate()'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>I cannot for the life of me figure out why one runs perfectly and the other fails. I suspect that I have linked something improperly, since this is my first time attempting to compile using a header file I wrote myself. If you believe that I have omitted something important in attempting to keep this readable, I have included a link to the github repo containing the full code at the beginning of this post.</p>
  
  <p>Thank you all so much.</p>