ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Creating generic topic subscribers with ShapeShifter

asked 2018-05-30 21:47:42 -0600

dheeranet gravatar image

updated 2018-05-31 00:23:41 -0600

jayess gravatar image

Hi all, I'm having trouble creating a generic topic subcriber that simply records the last time a message was published. Here are the relevant parts of my current code:

void cb_record_message_time(const ros::MessageEvent<topic_tools::ShapeShifter>& msg, uint64_t& message_time){
    ros::Time time = ros::Time::now();
    message_time = 1000 * (uint64_t)time.sec + (uint64_t)time.nsec / 1e6;

int main(int argc, char **argv) {
   ros::init(argc, argv, "topic_health_check");
   ros::NodeHandle nh;

   std::vector<std::string> topic_names = {

  uint64_t topic_message_times[256]; // if this is a std::vector then std::ref(topic_message_times[i]) doesn't work
  std::vector<ros::Subscriber> topic_subs;

for(int i = 0; i < topic_names.size(); i++) {
     topic_message_times[i] = 0;

     ros::Subscriber sub = nh.subscribe<topic_tools::ShapeShifter>(topic_names[i], 1, boost::bind(cb_record_message_time, _1, std::ref(topic_message_times[i])));

The ShapeShifter docs are sparse, the given example at doesn't compile, and most other examples on the web use nh.subscribe without the template type <> which also doesn't compile (I'm on Kinetic, not sure if that makes a difference). Any thoughts? Thanks!

Edit:: This is the error I get:

CMakeFiles/health_check.dir/src/health_check.cpp.o: In function ros::serialization::PreDeserialize<topic_tools::ShapeShifter>::notify(ros::serialization::PreDeserializeParams<topic_tools::ShapeShifter> const&)': health_check.cpp:(.text._ZN3ros13serialization14PreDeserializeIN11topic_tools12ShapeShifterEE6notifyERKNS0_20PreDeserializeParamsIS3_EE[_ZN3ros13serialization14PreDeserializeIN11topic_tools12ShapeShifterEE6notifyERKNS0_20PreDeserializeParamsIS3_EE]+0x24a): undefined reference to topic_tools::ShapeShifter::morph(std::__cxx11::basic_string<char, std::char_traits<char="">, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char="">, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char="">, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char="">, std::allocator<char> > const&)' CMakeFiles/health_check.dir/src/health_check.cpp.o: In function boost::detail::sp_if_not_array<topic_tools::ShapeShifter>::type boost::make_shared<topic_tools::ShapeShifter>()': health_check.cpp:(.text._ZN5boost11make_sharedIN11topic_tools12ShapeShifterEJEEENS_6detail15sp_if_not_arrayIT_E4typeEDpOT0_[_ZN5boost11make_sharedIN11topic_tools12ShapeShifterEJEEENS_6detail15sp_if_not_arrayIT_E4typeEDpOT0_]+0x77): undefined reference to topic_tools::ShapeShifter::ShapeShifter()' CMakeFiles/health_check.dir/src/health_check.cpp.o: In function ros::SubscriptionCallbackHelperT<boost::shared_ptr<topic_tools::ShapeShifter const> const&, void>::getTypeInfo()': health_check.cpp:(.text._ZN3ros27SubscriptionCallbackHelperTIRKN5boost10shared_ptrIKN11topic_tools12ShapeShifterEEEvE11getTypeInfoEv[_ZN3ros27SubscriptionCallbackHelperTIRKN5boost10shared_ptrIKN11topic_tools12ShapeShifterEEEvE11getTypeInfoEv]+0x9): undefined reference totypeinfo for topic_tools::ShapeShifter' collect2: error: ld returned 1 exit status
edit retag flag offensive close merge delete



What part of your code isn't working? what error are you getting?

ahendrix gravatar image ahendrix  ( 2018-05-30 22:48:31 -0600 )edit

._ZN3ros27SubscriptionCallbackHelperTIRKN5boost10shared_ptrIKN11topic_tools12ShapeShifterEEEvE11getTypeInfoEv[_ZN3ros27SubscriptionCallbackHelperTIRKN5boost10shared_ptrIKN11topic_tools12ShapeShifterEEEvE11getTypeInfoEv]+0x9): undefined reference to `typeinfo for topic_tools::ShapeShifter'

dheeranet gravatar image dheeranet  ( 2018-05-31 00:13:51 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-05-31 01:41:52 -0600

gvdhoorn gravatar image

updated 2021-09-30 14:11:05 -0600

That is a linker error, not a compilation problem. You're not linking against the libraries that are required.

Edit: since this is now an answer: make sure to link against topic_tools (ie: add it to find_package(catkin REQUIRED COMPONENTS ..). That's what provides ShapeShifter.

edit flag offensive delete link more


Demangled symbol:

ros::SubscriptionCallbackHelperT<boost::shared_ptr<topic_tools::ShapeShifter const> const&, void>::getTypeInfo()[ros::SubscriptionCallbackHelperT<boost::shared_ptr<topic_tools::ShapeShifter const> const&, void>::getTypeInfo()] 0x9)
gvdhoorn gravatar image gvdhoorn  ( 2018-05-31 01:42:35 -0600 )edit

@gvdhoorn Thanks! I got it to work.

dheeranet gravatar image dheeranet  ( 2018-05-31 04:31:26 -0600 )edit

@dheeranet How did you solve the problem? I'm stuck with a similar problem

teshansj gravatar image teshansj  ( 2018-08-31 01:55:21 -0600 )edit

@gvdhoorn Can you please explain in detail that where to change because I am also getting same error.

void topicCallback(const ShapeShifter::ConstPtr &msg, const std::string &topic_name)
  uint32_t length = msg->size();

  auto time = std::chrono::system_clock::now();
  double diff = std::chrono::duration<double>(time-last).count();

 boost::function<void(const ShapeShifter::ConstPtr &)> callback;
  callback = [topic_name](const ShapeShifter::ConstPtr &msg)
    topicCallback(msg, topic_name);

  ros::Subscriber subscriber = nh.subscribe(topic_name, 10, callback);
Aakin gravatar image Aakin  ( 2021-09-29 16:46:09 -0600 )edit

The problem is most likely in your CMakeLists.txt, which we don't see.

In any case, just to clarify: my answer here wasn't actually an answer, it was a comment. It appears to have been converted to an answer. That's why there is nothing more than a quick hint.

gvdhoorn gravatar image gvdhoorn  ( 2021-09-30 02:04:21 -0600 )edit


cmake_minimum_required(VERSION 2.8.3)

find_package(catkin REQUIRED COMPONENTS


include_directories(include ${catkin_INCLUDE_DIRS})





Aakin gravatar image Aakin  ( 2021-09-30 09:45:57 -0600 )edit

You already have #q387669. Why keep posting here as well?

gvdhoorn gravatar image gvdhoorn  ( 2021-09-30 13:12:34 -0600 )edit

Might make sense to post in both places. Google seems to rank this post higher so more people land here I think

dheeranet gravatar image dheeranet  ( 2021-09-30 13:49:27 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-05-30 21:43:10 -0600

Seen: 1,535 times

Last updated: Sep 30 '21