Undefined reference to RosIntrospection functions
Hey guys,
I try to convert the Raw Buffer of a ShapeShifter to its original DataType Structure. But I have Problems understanding the new API. In the wiki the author used functions, which are not available anymore, so I tried to do it with the latest headers available.
As I understand the new API, I have to register the MessageDefinition first and afterwards I can deserialize the Buffer IntoFlatContainer.
Copy of the ros_type_introspection.hpp: In the file is a short description to each function
void registerMessageDefinition(const std::string& message_identifier,
const ROSType &main_type,
const std::string& definition);
bool deserializeIntoFlatContainer(const std::string& msg_identifier,
absl::Span<uint8_t> buffer,
FlatMessage* flat_container_output,
const uint32_t max_array_size ) const;
Here is my code:
using namespace RosIntrospection;
static std::vector<uint8_t> buffer;
static FlatMessage flat_container;
Parser parser;
const std::string& datatype = msg->getDataType();
const std::string& definition = msg->getMessageDefinition();
ROS_INFO("datatype: %s", datatype.c_str() );
buffer.resize( msg->size() );
ros::serialization::OStream stream(buffer.data(), buffer.size());
msg->write(stream);
parser.registerMessageDefinition(datatype, ROSType("geometry_msgs/Twist"), definition);
The registration of the MessageDefinition fails. And functions like described in the wiki (e.g buildROSTypeMapFromDefinition) are not available anymore.
My current error message:
RosSender.cpp:(.text+0x3cc): undefined reference to `RosIntrospection::ROSType::ROSType(absl::string_view)'
RosSender.cpp:(.text+0x3ed): undefined reference to `RosIntrospection::Parser::registerMessageDefinition(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, RosIntrospection::ROSType const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
Can anyone tell me how to use the new API correctly to get the original message?
Thank you!!
edit (Add CMakeList.txt):
cmake_minimum_required(VERSION 2.8.3)
set(CMAKE_CXX_FLAGS "-std=c++11")
set(CMAKE_CXX_FLAGS "-std=c++14")
project(RosSender)
set(THIRDPARTY_DIR ${PROJECT_SOURCE_DIR}/../thirdParty)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
)
catkin_package(
INCLUDE_DIRS
LIBRARIES RosAdapter
CATKIN_DEPENDS roscpp rospy std_msgs
DEPENDS system_lib
)
include_directories(
${catkin_INCLUDE_DIRS}
)
include_directories(
${THIRDPARTY_DIR}
)
add_executable(RosSender src/RosSender.cpp)
target_link_libraries(RosSender ${catkin_LIBRARIES} ${THIRDPARTY_DIR}/oa/myOaLib.so)
target_link_libraries(RosSender /opt/ros/kinetic/lib/libtopic_tools.so)
The last error is a linker error, not something else.
So apparently the compiler is happy, but the linker can't find the specific symbol it needs to link your executable.
Are you enabling / using C++11 in your pkg and linking the
ros_type_introspection
libraries correctly?set(CMAKE_CXX_FLAGS "-std=c++11") set(CMAKE_CXX_FLAGS "-std=c++14") these are my link libraries: target_link_libraries(RosSender ${catkin_LIBRARIES}) target_link_libraries(RosSender /opt/ros/kinetic/lib/libtopic_tools.so) I don't have other *.so files to link
Please add this to your original question text. Comments are too limited.
re:
set(CMAKE_CXX_FLAGS ..)
: don't do this. If you must useset(..)
, useset(VAR "new entry $VAR")
so as to not override whatever was already there.Can you please add your complete
CMakeLists.txt
to your question?I don't understand why you're listing the absolute path to the
topic_tools
library like that.I had to add the path, because otherwise I got Linking Problems
Could I refer you to wiki/catkin/CMakeLists.txt?
topic_tools
is a Catkin pkg, so it should appear in yourfind_package(catkin REQUIRED COMPONENTS ..)
call.There are some other unusual things in your
CMakeLists.txt
file as well.Fi: you have
DEPENDS system_lib
in there. But you never actually build a library calledsystem_lib
. If you don't intend to, remove theDEPENDS system_lib
line.Could you also please use the Preformatted Text button when copy-pasting code/build scripts/console text? It's the one with
101010
on it. That would make things much easier to read.Thanks.