Linker's Error while using ShapeShifter
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)
Can you show the error pls
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 totopic_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::detailCheck this answer #q292757. It’s similar. Hope it helps
I am unable to understand the solution.
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
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 I have updated my question and included my CMakeLists.txt and entire error message.