diagnostics icon indicating copy to clipboard operation
diagnostics copied to clipboard

ROS2 Missing ament_export_target in diagnostic_aggregation CMake

Open AzaelCicero opened this issue 3 years ago • 1 comments

I am writing my own plugin for the diagnostic and I needed to call StatusItem::toStatusMsg https://github.com/ros/diagnostics/blob/galactic/diagnostic_aggregator/include/diagnostic_aggregator/status_item.hpp#L222-L224

I was getting a linking error:

/usr/bin/ld: libas_monitor_analyzers_lib.so: undefined reference to `diagnostic_aggregator::StatusItem::toStatusMsg(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, bool) const' collect2: error: ld returned 1 exit status make[2]: *** [CMakeFiles/as_monitor_analyzers_test.dir/build.make:210: as_monitor_analyzers_test] Error 1 make[1]: *** [CMakeFiles/Makefile2:125: CMakeFiles/as_monitor_analyzers_test.dir/all] Error 2 make: *** [Makefile:141: all] Error 2

The issue is that CMake does not export the diagnostic_aggregator library: https://github.com/ros/diagnostics/blob/galactic/diagnostic_aggregator/CMakeLists.txt#L158-L164

It should look like this:

ament_export_targets(${PROJECT_NAME} HAS_LIBRARY_TARGET)
ament_export_libraries(${PROJECT_NAME})

Is it by design?

AzaelCicero avatar Sep 17 '22 18:09 AzaelCicero

This PR added that line for ament_export_targets. ament_export_libraries is not needed if you use ament_export_targets according to this.

I think this issue can be closed.

RFRIEDM-Trimble avatar Nov 16 '22 04:11 RFRIEDM-Trimble

I agree. I think we can close this

ct2034 avatar Nov 21 '22 13:11 ct2034