ROS2 interfacing with gazebo causes gzserver: symbol lookup error

asked 2019-08-05 12:34:14 -0500

fremad gravatar image

updated 2019-08-05 14:36:47 -0500

Trying to make a plugin for gazebo connected with ROS2. I am using the rclcpp API but creating subscriptions is cauting errors. The load function is shown below:

void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf)
{

    int argc = 0;
    char **argv = NULL;
    rclcpp::init(argc, argv);
    // rclcpp::spin(std::make_shared<MinimalSubscriber>());
    // rclcpp::shutdown();
    auto node = rclcpp::Node::make_shared("ObiWan");
    node->create_subscription<std_msgs::msg::String>(
        "topic",
        10,
        [node](std_msgs::msg::String::UniquePtr msg) {
            RCLCPP_INFO(node->get_logger(), "I heard: '%s'", msg->data.c_str());
        });


    //Logs to node log, pretty cool really! :D
    RCLCPP_INFO(node->get_logger(),
                "PLease help me kenobi '%s'", node->get_name());
}

The problem seems to arrive when calling the create_subscription(...).

I get the error:

gzserver: symbol lookup error: /home/lars/gaz-tryout3/build/libhello_world.so: undefined symbol: _ZN22rosidl_typesupport_cpp31get_message_type_support_handleIN8std_msgs3msg7String_ISaIvEEEEEPK29rosidl_message_type_support_tv

any ideas for a fix, or some info on why this is happening?

Running gazebo9 ROS2 dashing and ros-dashing-gazebo-ros-pkgs

cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
set (CMAKE_CXX_STANDARD 11)
find_package(gazebo REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)

include_directories(${rclcpp_INCLUDE_DIRS})
include_directories(${std_msgs_INCLUDE_DIRS})
include_directories(${GAZEBO_INCLUDE_DIRS})
link_directories(${GAZEBO_LIBRARY_DIRS})
list(APPEND CMAKE_CXX_FLAGS "${GAZEBO_CXX_FLAGS}")

add_library(hello_world SHARED hello_world.cc)
target_link_libraries(hello_world ${GAZEBO_LIBRARIES} ${rclcpp_LIBRARIES})

You were right, forgot to link the std_msgs. I linked them properly and now it works :)

target_link_libraries(hello_world ${GAZEBO_LIBRARIES} ${rclcpp_LIBRARIES} ${std_msgs_LIBRARIES})

If anybody needs the same

edit retag flag offensive close merge delete

Comments

Could you also give your CMakeLists.txt? It looks to me as if you don't link correctly to your std_msgs packages and/or haven't sourced your ROS2 installation correctly before building.

Karsten gravatar imageKarsten ( 2019-08-05 14:15:33 -0500 )edit

Please edit your original question text, comments are not suited for posting code or build scripts.

Use the edit button/link for that.

gvdhoorn gravatar imagegvdhoorn ( 2019-08-05 14:25:58 -0500 )edit

Please post the last part of your question text (that you added in your last edit) as an answer and accept your own answer.

That will show clearly that your question was answered.

gvdhoorn gravatar imagegvdhoorn ( 2019-08-05 14:39:16 -0500 )edit