ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Linker's Error while using ShapeShifter

asked 2021-09-29 16:21:39 -0500

Aakin gravatar image

updated 2021-09-30 13:13:14 -0500

gvdhoorn gravatar image

I am getting linker's error while try to use ShapeShifter for getting size of ROS topic. Here is code:-

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

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

ros::init(argc, argv, "universal_subscriber");
  ros::NodeHandle nh;

  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);

Error Message:

tp.cpp:(.text+0x2f): undefined reference to `topic_tools::ShapeShifter::size() const'
CMakeFiles/roshz.dir/src/tp.cpp.o: In function `ros::serialization::PreDeserialize<topic_tools::ShapeShifter>::notify(ros::serialization::PreDeserializeParams<topic_tools::ShapeShifter> const&)':
tp.cpp:(.text._ZN3ros13serialization14PreDeserializeIN11topic_tools12ShapeShifterEE6notifyERKNS0_20PreDeserializeParamsIS3_EE[_ZN3ros13serialization14PreDeserializeIN11topic_tools12ShapeShifterEE6notifyERKNS0_20PreDeserializeParamsIS3_EE]+0x243): 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/roshz.dir/src/tp.cpp.o: In function `boost::detail::sp_if_not_array<topic_tools::ShapeShifter>::type boost::make_shared<topic_tools::ShapeShifter>()':
tp.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/roshz.dir/src/tp.cpp.o: In function `ros::SubscriptionCallbackHelperT<boost::shared_ptr<topic_tools::ShapeShifter const> const&, void>::getTypeInfo()':
tp.cpp:(.text._ZN3ros27SubscriptionCallbackHelperTIRKN5boost10shared_ptrIKN11topic_tools12ShapeShifterEEEvE11getTypeInfoEv[_ZN3ros27SubscriptionCallbackHelperTIRKN5boost10shared_ptrIKN11topic_tools12ShapeShifterEEEvE11getTypeInfoEv]+0xb): undefined reference to `typeinfo for topic_tools::ShapeShifter'
collect2: error: ld returned 1 exit status

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(roshz)

find_package(catkin REQUIRED COMPONENTS
  roscpp
)

catkin_package(
    INCLUDE_DIRS
    CATKIN_DEPENDS roscpp
  )

include_directories(include ${catkin_INCLUDE_DIRS})
link_directories(${catkin_LIBRARY_DIRS})
add_definitions(${catkin_DEFINITIONS})

add_compile_options(-std=c++11)
add_executable(${PROJECT_NAME}
  src/roshz.cpp
  src/statistics.cpp
  src/tp.cpp
)

target_link_libraries(${PROJECT_NAME}
  ${catkin_LIBRARIES}
)

set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
edit retag flag offensive close merge delete

Comments

Can you show the error pls

osilva gravatar image osilva  ( 2021-09-29 20:32:12 -0500 )edit

tp.cpp:(.text+0x2f): undefined reference to topic_tools::ShapeShifter::size() const' CMakeFiles/roshz.dir/src/tp.cpp.o: In functionros::serialization::PreDeserialize<topic_tools::shapeshifter>::notify(ros::serialization::PreDeserializeParams<topic_tools::shapeshifter> const&)': tp.cpp:(.text._ZN3ros13serialization14PreDeserializeIN11topic_tools12ShapeShifterEE6notifyERKNS0_20PreDeserializeParamsIS3_EE[_ZN3ros13serialization14PreDeserializeIN11topic_tools12ShapeShifterEE6notifyERKNS0_20PreDeserializeParamsIS3_EE]+0x243): 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/roshz.dir/src/tp.cpp.o: In functionboost::detail

Aakin gravatar image Aakin  ( 2021-09-29 20:42:22 -0500 )edit

Check this answer #q292757. It’s similar. Hope it helps

osilva gravatar image osilva  ( 2021-09-29 20:48:29 -0500 )edit

I am unable to understand the solution.

Aakin gravatar image Aakin  ( 2021-09-29 20:50:47 -0500 )edit

I just read your comment. Take a look at this answer #q197132 is about linker errors. It’s getting late here. Hope it helps and will check tomorrow morning

osilva gravatar image osilva  ( 2021-09-29 20:58:51 -0500 )edit

Linker errors are commonly caused by libraries / packages which are not linked against. That's all configured in your CMakeLists.txt. You don't show that in your question, so we can't help you.

Also: please add the actual, full, error message to your question. Not in a comment.

gvdhoorn gravatar image gvdhoorn  ( 2021-09-30 02:36:38 -0500 )edit

@gvdhoorn I have updated my question and included my CMakeLists.txt and entire error message.

Aakin gravatar image Aakin  ( 2021-09-30 07:45:30 -0500 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2021-09-30 13:13:53 -0500

gvdhoorn gravatar image

ShapeShifter is in topic_tools, not roscpp. You're not linking against the required libraries.

edit flag offensive delete link more

Comments

Thanks a lot

Aakin gravatar image Aakin  ( 2021-09-30 13:21:56 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2021-09-29 16:21:39 -0500

Seen: 208 times

Last updated: Sep 30 '21