macOS | Foxy | issue with linking std_msgs
Hi,
I'm using ROS2 Foxy on macOS Catalina.
I'm able to run turtlesim node as well as simplest node written by myself. However when I try to create publisher with type std_msgs::msg::String I got error:
Undefined symbols for architecture x86_64: "rosidl_message_type_support_t const* rosidl_typesupport_cpp::get_message_type_support_handle<std_msgs::msg::string_<std::__1::allocator<void> > >()", referenced from: rclcpp::Publisher<std_msgs::msg::string_<std::__1::allocator<void> >, std::__1::allocator<void> >::Publisher(rclcpp::node_interfaces::NodeBaseInterface, std::__1::basic_string<char, std::__1::char_traits<char="">, std::__1::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::__1::allocator<void> > const&) in number_publisher.cpp.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: [number_publisher_node] Error 1 make[1]: [CMakeFiles/number_publisher_node.dir/all] Error 2 make: ** [all] Error 2
Code looks as follows:
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
class NumberPublisher : public rclcpp::Node
{
private:
void timer_callback()
{
auto msg = std_msgs::msg::String();
msg.data = "2";
m_publisher->publish(msg);
}
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr m_publisher;
rclcpp::TimerBase::SharedPtr m_timer;
public:
NumberPublisher() : Node("number_publisher")
{
m_publisher = this->create_publisher<std_msgs::msg::String>("topic", 10);
m_timer = this->create_wall_timer(std::chrono::seconds(1), std::bind(&NumberPublisher::timer_callback, this));
RCLCPP_INFO(this->get_logger(), "NumberPublisher created");
}
};
int main(int argc, char **argv)
{
rclcpp::init(argc, argv);
auto node = std::make_shared<NumberPublisher>();
rclcpp::spin(node);
rclcpp::shutdown();
return 0;
}
In CMakeList.txt I added:
find_package(std_msgs REQUIRED)
In package.xml I added:
<depend>std_msgs</depend>
How did you install Foxy? FWIW, only macOS Mojave is officially supported for Foxy.
Also, in your CMakeLists.txt you should make sure you are linking your executable against
std_msgs
. E.g. with ament:ament_target_dependencies(number_publisher_node "std_msgs")
@jacobperron To install Foxy on macOS I followed the instruction on ros.org After many issues I decided to install Ubuntu on my mac and am starting with ROS on it. Unfortunately I already removed that ROS project and can't check in CMakeLists.txt if I linked executables against std_msg, but I think I did. Thanks for reply!