title: Build error : undefined reference to `cv_bridge::CvImage::toImageMsg() const'
body: <p>I am using ROS Kinetic and trying to write a program that would read two videos and publish them on two different topics. But I think I've made some mistake in linking OpenCV libraries. I am getting the following errors.</p>
  
  <pre><code>CMakeFiles/src.dir/src/src.cpp.o: In function `main':
  src.cpp:(.text+0x3fd): undefined reference to `cv_bridge::CvImage::toImageMsg() const'
  src.cpp:(.text+0x56d): undefined reference to `cv_bridge::CvImage::toImageMsg() const'
  collect2: error: ld returned 1 exit status
  MultiCamImages/CMakeFiles/src.dir/build.make:165: recipe for target 'MultiCamImages/src' failed
  make[2]: *** [MultiCamImages/src] Error 1
  CMakeFiles/Makefile2:1089: recipe for target 'MultiCamImages/CMakeFiles/src.dir/all' failed
  make[1]: *** [MultiCamImages/CMakeFiles/src.dir/all] Error 2
  Makefile:138: recipe for target 'all' failed
  make: *** [all] Error 2
  Invoking "make -j4 -l4" failed
  </code></pre>
  
  <p>This is my source file:</p>
  
  <pre><code>#include &lt;ros/ros.h&gt;
  #include &lt;cv_bridge/cv_bridge.h&gt;
  #include &lt;image_transport/image_transport.h&gt;
  #include &lt;sensor_msgs/image_encodings.h&gt;
  
  #include &lt;opencv2/opencv.hpp&gt;
  
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  int main(int argc, char** argv){
      ros::init(argc, argv, "PublishMultiCamImages");
  
      ros::NodeHandle nh;
  
      image_transport::ImageTransport it(nh);
      image_transport::Publisher pub1 = it.advertise("/camera/image_raw1", 1);
      image_transport::Publisher pub2 = it.advertise("/camera/image_raw2", 1);
  
      cv::Mat im;
      cv::String Path1("/home/akanksha/COSLAM_Dataset/EA-01/grayscale/*.jpg");
      cv::String Path2("/home/akanksha/COSLAM_Dataset/EA-02/grayscale/*.jpg");
  
      //time = ros::Time::now();
  
      vector&lt;cv::String&gt; fn1;
      vector&lt;cv::String&gt; fn2;
      cv::glob(Path1,fn1, true); // recurse
      cv::glob(Path2,fn2, true);
  
      ros::Rate r(50);
  
      int l1 = fn1.size();
      int l2 = fn2.size();
  
      int count1 = 0, count2 = 0;
      bool flag;
      while(ros::ok()){
          flag = true;
          if(count1 &lt; l1){
              cv::Mat image1 = cv::imread(fn1[count1]);
              sensor_msgs::ImagePtr msg1 = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image1).toImageMsg();
              pub1.publish(msg1);
              count1++;
              flag = false;
          }
          if(count2 &lt; l2){
              cv::Mat image2 = cv::imread(fn2[count2]);
              sensor_msgs::ImagePtr msg2 = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image2).toImageMsg();
              pub2.publish(msg2);
              count2++;
              flag = false;
          }
  
          if(flag)
              break;
  
          r.sleep();
      }
  
      ros::shutdown();
  
      return 0;
  
  
  }
  </code></pre>
  
  <p>This is my CMakeLists.txt</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.8.3)
  project(MultiCamImages)
  
  find_package(catkin REQUIRED COMPONENTS
    roscpp
    image_transport
    OpenCV
  )
  # find_package(OpenCV REQUIRED)
  
  set(OpenCV_LIBS opencv_core opencv_imgproc opencv_calib3d opencv_video opencv_features2d opencv_ml opencv_highgui opencv_objdetect)
  
  add_executable(src src/src.cpp)
  target_link_libraries(src ${catkin_LIBRARIES} ${OpenCV_LIBS})
  
  catkin_package(
  #  INCLUDE_DIRS include
  #  LIBRARIES MultiCamImages
  #  CATKIN_DEPENDS roscpp
  #  DEPENDS system_lib
  )
  
  include_directories(
    ${catkin_INCLUDE_DIRS}
  )
  </code></pre>
  
  <p>And this is my pakage.xml</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;package&gt;
    &lt;name&gt;MultiCamImages&lt;/name&gt;
    &lt;version&gt;0.0.0&lt;/version&gt;
    &lt;description&gt;The MultiCamImages package&lt;/description&gt;
  
    &lt;maintainer email="akanksha@todo.todo"&gt;akanksha&lt;/maintainer&gt;
  
    &lt;buildtool_depend&gt;catkin&lt;/buildtool_depend&gt;
    &lt;build_depend&gt;roscpp&lt;/build_depend&gt;
    &lt;run_depend&gt;roscpp&lt;/run_depend&gt;
    &lt;build_depend&gt;sensor_msgs&lt;/build_depend&gt;
    &lt;run_depend&gt;sensor_msgs&lt;/run_depend&gt;
    &lt;build_depend&gt;cv_bridge&lt;/build_depend&gt;
    &lt;run_depend&gt;cv_bridge&lt;/run_depend&gt;
  
  &lt;/package&gt;
  </code></pre>
  
  <p>If you could point out the problem that would be a great help. Thanks! </p>