colcon build error: Target "<my_lib>" links to target "std_msgs::std_msgs__rosidl_generator_c" but the target was not found
I am trying to convert the inertial_sense_ros package to ROS2 and am getting a strange error when I try to build. I am using ROS2 Foxy on Ubuntu 20.04.
Initially, I get an error that my library cannot find rclcpp
In file included from /home/boatlanding/is_ws/src/inertial-sense-ros/src/inertial_sense_ros.cpp:1:
/home/boatlanding/is_ws/src/inertial-sense-ros/include/inertial_sense_ros.h:11:10: fatal error: rclcpp/rclcpp.hpp: No such file or directory
11 | #include "rclcpp/rclcpp.hpp"
And I get that using the following CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
project(inertial_sense_ros)
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(Threads)
# setup targets
include_directories(include
${ament_INCLUDE_DIRS}
lib/inertial-sense-sdk/src #This line of CMakeList.txt stays in .external file to reference submodule
)
add_subdirectory(lib/inertial-sense-sdk)
add_library(inertial_sense_ros_lib
src/inertial_sense_ros.cpp
)
target_link_libraries(inertial_sense_ros_lib ${rclcpp_LIBRARIES} InertialSense pthread) # ${ament_LIBRARIES}
add_executable(inertial_sense_node src/inertial_sense_node.cpp)
add_dependencies(inertial_sense_node inertial_sense_ros_lib)
# export information to downstream packages
ament_export_dependencies(
rosidl_default_runtime
rclcpp
sensor_msgs
geometry_msgs
)
ament_export_include_directories(include)
ament_export_libraries(inertial_sense_ros_lib)
ament_package()
# install artifacts
install(
DIRECTORY include/
DESTINATION include
)
install(
TARGETS inertial_sense_ros_lib inertial_sense_node
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
I tried fixing this error by simply adding the rclcpp_LIBRARIES to my target_link_libraries target_link_libraries(inertial_sense_ros_lib ${rclcpp_LIBRARIES} InertialSense pthread)
adding this and trying to build with colcon build
leads to the following error repeated 10-20 times:
Starting >>> inertial_sense_ros
--- stderr: inertial_sense_ros
CMake Error at CMakeLists.txt:55 (add_library):
Target "inertial_sense_ros_lib" links to target
"std_msgs::std_msgs__rosidl_generator_c" but the target was not found.
Perhaps a find_package() call is missing for an IMPORTED target, or an
ALIAS target is missing?
CMake Error at CMakeLists.txt:55 (add_library):
Target "inertial_sense_ros_lib" links to target
"std_msgs::std_msgs__rosidl_typesupport_introspection_c" but the target was
not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:55 (add_library):
Target "inertial_sense_ros_lib" links to target
"std_msgs::std_msgs__rosidl_typesupport_c" but the target was not found.
Perhaps a find_package() call is missing for an IMPORTED target, or an
ALIAS target is missing?
CMake Error at CMakeLists.txt:55 (add_library):
Target "inertial_sense_ros_lib" links to target
"std_msgs::std_msgs__rosidl_generator_cpp" but the target was not found.
Perhaps a find_package() call is missing for an IMPORTED target, or an
ALIAS target is missing?
I'm confused by this error as it doesn't seem to be referring to a package that I could include. In fact CMake seems to be looking for a combination of two packages: std_msgs and rosidl_generator_cpp. Adding packages rosidl_generator_cpp
or rosidl_typesupport_c
has no effect on this error. From what I have found, rosidl_generator is usually used for custom messages and services, but in my case I don't have any. Still new to using colcon and ament so any help would be much appreciated.
Hi, have you already found a solution to this? I have the same issue with you