0
$\begingroup$

I need cv_bridge on my cmakelist.txt. Cmakelist shows a path for cv_bridge.h, however there is no file on that name at that path.

I have opencv 4.5.4,ros2 humble.

I tried to install cv_bridge by following this however, cmake still looks at another path.

What do I need to fix this problem?

Cmakelist.txt:

cmake_minimum_required(VERSION 3.5)
project(synchroniz_wo)

# Find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(cv_bridge REQUIRED) 
find_package(OpenCV REQUIRED)
find_package(pcl_conversions REQUIRED)
find_package(PCL REQUIRED)
find_package(message_filters REQUIRED)

# Include directories
include_directories(
  include
  ${rclcpp_INCLUDE_DIRS}
  ${sensor_msgs_INCLUDE_DIRS}
  ${cv_bridge_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS}
  ${PCL_INCLUDE_DIRS}
  ${message_filters_INCLUDE_DIRS}
  ${pcl_conversions_INCLUDE_DIRS}
)

# Add the executable
add_executable(synchroniz_wo ${CMAKE_CURRENT_SOURCE_DIR}/synchroniz_wo.cpp)

# Link libraries
target_link_libraries(synchroniz_wo
  ${rclcpp_LIBRARIES}
  ${sensor_msgs_LIBRARIES}
  ${OpenCV_LIBRARIES}
  ${cv_bridge_LIBRARIES}
  ${PCL_LIBRARIES}
  ${message_filters_LIBRARIES}
  ${pcl_conversions_LIBRARIES}
)

# Output information for debugging
message(STATUS "CV Bridge Include Directory: ${cv_bridge_INCLUDE_DIRS}")
message(STATUS "CV Bridge Library: ${cv_bridge_LIBRARIES}")

# Install the executable
install(TARGETS synchroniz_wo
  DESTINATION lib/${PROJECT_NAME})

ament_package()

The error when I run make command:

synchroniz_wo.cpp:13:10: fatal error: cv_bridge/cv_bridge.h: No such file or directory
   13 | #include <cv_bridge/cv_bridge.h>

The path:

-- CV Bridge Include Directory: 

/usr/include/opencv4;/opt/ros/humble/include/sensor_msgs
-- CV Bridge Library: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_stitching;opencv_video...etc.
$\endgroup$

1 Answer 1

0
$\begingroup$

Something like this usually works for me:

ament_target_dependencies(synchronize_wo cv_bridge)

When using ament_target_dependencies you should not have to explicitly list the include and library files. Also not when you use target_link_libraries(synchronize_wo cv_bridge::cv_bridge)

$\endgroup$
1
  • $\begingroup$ Oh, and make sure to also look for cv_bridge.hpp . The suffix has changed recently. $\endgroup$ Commented Sep 26 at 11:01

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.