Rosanswers logo

I run a simple program to continuously publish image to ROS server. I cannot get rid of below error, anyone know the solution please help.

#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h>

int main(int argc, char** argv)
  ros::init(argc, argv, "image_publisher");
  ros::NodeHandle nh;

  image_transport::ImageTransport it(nh);
  image_transport::Publisher pub = it.advertise("camera/image", 1);
  cv::Mat image = cv::imread(argv[1], cv::IMREAD_COLOR);
  sensor_msgs::ImagePtr msg = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image).toImageMsg();

 ros::Rate loop_rate(5);
  while (nh.ok()) {


[ 97%] Built target vtd2ros_generate_messages_lisp
[ 97%] Built target vtd2ros_generate_messages
/usr/bin/ld: cannot find -lopencv_xphoto}
collect2: error: ld returned 1 exit status
make[2]: *** [vtd2ros/CMakeFiles/camera.dir/build.make:207: `/home/robotest/RoboTest/Vu_2/vtd2ros/devel/lib/vtd2ros/camera] Error 1`
make[1]: *** [CMakeFiles/Makefile2:685: vtd2ros/CMakeFiles/camera.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
Invoking "make -j16 -l16" failed

The content of CMakelist.txt

find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs genmsg message_generation cv_bridge image_transport)
find_package( OpenCV REQUIRED )

include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable(camera src/camera.cpp )
add_dependencies(camera ${camera_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})



OpenCV version 4.2.0

I also install sudo apt-get install ros-noetic-vision-opencv

Originally posted by sgttrieu on ROS Answers with karma: 16 on 2021-06-24

Post score: 0


1 Answer 1


Rosanswers logo

The problem is solved. I did not pay attention that I leave a " } " in the target_link_libraries configuration.

Originally posted by sgttrieu with karma: 16 on 2021-06-25

This answer was ACCEPTED on the original site

Post score: 0


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.