0
$\begingroup$

Rosanswers logo

I am trying to do wiki.ros.org/cv_bridge/Tutorials/UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages

But I get this error:

Linking CXX executable image_converter > CMakeFiles/image_converter.dir/src/image_converter.cpp.o: > In function main': > image_converter.cpp:(.text+0x50): > undefined reference to > ros::init(int&, char**, > std::basic_string<char, > std::char_traits, > std::allocator > const&, > unsigned int)'

and so on

My CmakeLists.txt

cmake_minimum_required(VERSION 2.8.3) project(learning_image_transport)

find_package(OpenCV)
include_directories(${OpenCV_INCLUDE_DIRS}) > add_executable(image_converter > src/image_converter.cpp) > target_link_libraries(image_converter > ${OpenCV_LIBRARIES})

find_package(catkin REQUIRED COMPONENTS genmsg cv_bridge

image_transport roscpp std_msgs )

And Package.xml

<buildtool_depend>catkin</buildtool_depend> <buildtool_depend>genmsg</buildtool_depend> <build_depend>image_transport</build_depend> <build_depend>roscpp</build_depend>
<build_depend>std_msgs</build_depend> <build_depend>cv_bridge</build_depend> <build_depend>opencv2</build_depend>
<run_depend>opencv2</run_depend>
<run_depend>cv_bridge</run_depend>
<run_depend>image_transport</run_depend> <run_depend>roscpp</run_depend>
<run_depend>std_msgs</run_depend>


Originally posted by ProstoTsar on ROS Answers with karma: 3 on 2014-01-15

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Besides ${OpenCV_LIBRARIES} you need to link your exec against ${catkin_LIBRARIES}:

target_link_libraries(image_converter ${OpenCV_LIBRARIES} ${catkin_LIBRARIES} )

Note that you need to call

find_package(catkin REQUIRED COMPONENTS genmsg cv_bridge image_transport roscpp std_msgs )

before target_link_libraries


Originally posted by Wolf with karma: 7555 on 2014-01-15

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by ProstoTsar on 2014-01-16:
I have already tried this but nothing changed

Comment by Wolf on 2014-01-16:
Looking at the order in your CMakeLists.txt: Could be that you have to call 'find_package(catkin REQUIRED COMPONENTS genmsg cv_bridge image_transport roscpp std_msgs )' before add_executable and target_link_libraries ....?

Comment by ProstoTsar on 2014-01-16:
No, my Cmakelists order is: include_directories(${catkin_INCLUDE_DIRS}) find_package(OpenCV) ... add_executable... target_link_libraries.... CATKIN_DEPENDS roscpp std_msgs cv_bridge image_geometry image_transport DEPENDS system_lib opencv genmsg find_package(catkin REQUIRED COMPONENTS ...

Comment by Wolf on 2014-01-16:
Why don't you put find_package( catkin REQUIRED COMPONENTS ... to the top of your file, ( before target_link_libraries(image_converter ${OpenCV_LIBRARIES} ${catkin_LIBRARIES} ) ? The var ${catkin_LIBRARIES} depends on it, so I think find_package( catkin must be called first!?

Comment by ProstoTsar on 2014-01-16:
Thanks a lot, now it is everything OK

$\endgroup$

Your Answer

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