diff --git a/ros/src/foxglove_bridge/src/message_definition_cache.cpp b/ros/src/foxglove_bridge/src/message_definition_cache.cpp index 9c975f973..61a8e340b 100644 --- a/ros/src/foxglove_bridge/src/message_definition_cache.cpp +++ b/ros/src/foxglove_bridge/src/message_definition_cache.cpp @@ -215,7 +215,19 @@ const MessageSpec& MessageDefinitionCache::load_message_spec( } // Get the package share directory, or throw a PackageNotFoundError - const std::string share_dir = ament_index_cpp::get_package_share_directory(package); + // Suppress deprecation warnings for this API call. The newer API signature + // (taking std::filesystem::path& as an out parameter) is only available in + // ROS 2 rolling and later distributions. To support older distributions, + // we continue using the old API until all supported distributions have been updated. +#if defined(__GNUC__) || defined(__clang__) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + const std::string share_dir_str = ament_index_cpp::get_package_share_directory(package); +#if defined(__GNUC__) || defined(__clang__) + #pragma GCC diagnostic pop +#endif + const std::filesystem::path share_dir(share_dir_str); // Get the rosidl_interfaces index contents for this package std::string index_contents; @@ -234,7 +246,7 @@ const MessageSpec& MessageDefinitionCache::load_message_spec( } // Read the file - const std::string full_path = share_dir + std::filesystem::path::preferred_separator + *it; + const std::filesystem::path full_path = share_dir / *it; std::ifstream file{full_path}; if (!file.good()) { throw DefinitionNotFoundError(definition_identifier.package_resource_name);