Robotics StackExchange | Archived questions

Linking CXX executable error, undefined reference to TinyXml

Hello everyone,

I am trying to compile catkinmake on this project more than a month now that is why I am desperately putting it up to the forum, I would be very grateful if you could help me with this somehow, I downloaded a repository from github: https://github.com/philip-long/cabledrivenrobot and could compile it with ROS Kinetic but since I experienced some issues in the code I asked the author in what environment was he working with it, so I installed ROS Indigo in the suitable ubuntu version and I cant compile the same code ever since. I get a message from catkinmake:

Linking CXX executable /home/aron/catkin_ws/devel/lib/br_motor_driver/ros_driver
[ 14%] Built target _cable_rob_generate_messages_check_deps_cable_msgs
[ 14%] Built target sensor_msgs_generate_messages_cpp
[ 14%] Built target std_msgs_generate_messages_cpp
[ 14%] Built target geometry_msgs_generate_messages_cpp
[ 14%] Built target trajectory_msgs_generate_messages_cpp
/home/aron/catkin_ws/devel/lib/libbr_robot.so: undefined reference to `vtable for TiXmlDocument'
/home/aron/catkin_ws/devel/lib/libbr_robot.so: undefined reference to `TiXmlNode::~TiXmlNode()'
/home/aron/catkin_ws/devel/lib/libbr_robot.so: undefined reference to `TiXmlElement::QueryDoubleAttribute(char const*, double*) const'
/home/aron/catkin_ws/devel/lib/libbr_robot.so: undefined reference to `TiXmlElement::SetAttribute(std::string const&, std::string const&)'
/home/aron/catkin_ws/devel/lib/libbr_robot.so: undefined reference to `TiXmlDocument::Accept(TiXmlVisitor*) const'
/home/aron/catkin_ws/devel/lib/libbr_robot.so: undefined reference to `TiXmlNode::FirstChildElement(char const*) const'
/home/aron/catkin_ws/devel/lib/libbr_robot.so: undefined reference to `TiXmlElement::TiXmlElement(std::string const&)'
/home/aron/catkin_ws/devel/lib/libbr_robot.so: undefined reference to `TiXmlDocument::TiXmlDocument()'
/home/aron/catkin_ws/devel/lib/libbr_robot.so: undefined reference to `TiXmlElement::QueryBoolAttribute(char const*, bool*) const'
/home/aron/catkin_ws/devel/lib/libbr_robot.so: undefined reference to `TiXmlNode::LinkEndChild(TiXmlNode*)'
/home/aron/catkin_ws/devel/lib/libbr_robot.so: undefined reference to `TiXmlDocument::Parse(char const*, TiXmlParsingData*, TiXmlEncoding)'
/home/aron/catkin_ws/devel/lib/libbr_robot.so: undefined reference to `vtable for TiXmlPrinter'
/home/aron/catkin_ws/devel/lib/libbr_robot.so: undefined reference to `TiXmlElement::TiXmlElement(char const*)'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/aron/catkin_ws/devel/lib/br_motor_driver/ros_driver] Error 1
make[1]: *** [cable_driven_robot/br_motor_driver/CMakeFiles/ros_driver.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 14%] Built target _cable_rob_generate_messages_check_deps_robot_cables_msgs
make: *** [all] Error 2
Invoking "make -j2 -l2" failed

I searched a lot of forums where I followed there advice, by installing the tinyxml library again, installed aptitude and installed tinyxml as a package, still didnt work, I installed various versions of tinyxml, still no success I get the same message where it wont be able to create the executable ros_driver I checked the CmakeLists.txt file and followed this tutorial: http://wiki.ros.org/tinyxml to see if there is some error but I couldn't find any, it should work just as it works in ROS Kinetic :/

Also if I run:

# apt search tinyxml

Sorting... Done
Full Text Search... Done
libtinyxml-dev/trusty,now 2.6.2-2 amd64 [installed]
  TinyXml library - header and static library

libtinyxml-doc/trusty 2.6.2-2 all
  TinyXml library - documentation files

libtinyxml2-0.0.0/trusty,now 0~git20120518.1.a2ae54e-1 amd64 [installed,automatic]
  C++ XML parsing library

libtinyxml2-2/trusty-backports 2.1.0-1~ubuntu14.04.1 amd64
  C++ XML parsing library

libtinyxml2-dev/trusty,now 0~git20120518.1.a2ae54e-1 amd64 [installed]
  TinyXML2 library - header and static library

libtinyxml2.6.2/trusty,now 2.6.2-2 amd64 [installed,automatic]
  C++ XML parsing library

libtinyxml2.6.2-dbg/trusty 2.6.2-2 amd64
  TinyXml library - debug files

I get the correct result I suppose, that it is intalled, although I have a feeling that ROS cant find that library anyway.

I am pasting the CmakeLists file as well just in case:

cmake_minimum_required(VERSION 2.8.3)
project(br_motor_driver)

Find catkin macros and libraries
if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
is used, also find other catkin packages

set(MSG_DEPS
  sensor_msgs
)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  roslib
  genmsg ${MSG_DEPS}
  cmake_modules
)

find_package(TinyXML REQUIRED)


catkin_package(
  INCLUDE_DIRS include
  LIBRARIES ${PROJECT_NAME}
  CATKIN_DEPENDS roscpp roslib  ${MSG_DEPS}
  DEPENDS  TinyXML
)

###########
## Build ##
###########

include(CheckCXXCompilerFlag)

CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)

CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)

if(COMPILER_SUPPORTS_CXX11)
    set(CMAKE_CXX_FLAGS "-std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
    set(CMAKE_CXX_FLAGS "-std=c++0x")
else()
    message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++  compiler. Suggested solution: update the pkg build-essential ")
endif()


Specify additional locations of header files

Your package locations should be listed before other locations

include_directories(include)

include_directories(
  include
  ${catkin_INCLUDE_DIRS}
  ${TinyXML_INCLUDE_DIRS}
  )

 Add cmake target dependencies of the library as an example, code may need to be generated before libraries either from message generation or dynamic reconfigure

 add_dependencies(br_driver ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

add_library(br_robot src/br_robot.cpp)
add_library(${PROJECT_NAME} src/ros_driver.cpp include/br_motor_driver/br_robot.h )

 Declare a C++ executable


add_executable(ros_driver src/ros_driver.cpp)
target_link_libraries(ros_driver br_robot ${catkin_LIBRARIES} ${TinyXML_LIBRARIES})

add_executable(friction_identification src/friction_identification.cpp)
target_link_libraries(friction_identification ${catkin_LIBRARIES} )

add_executable(robot_simulator src/robot_simulator.cpp)
target_link_libraries(robot_simulator ${catkin_LIBRARIES} ${TinyXML_LIBRARIES})

Asked by AaronM on 2019-03-08 05:30:32 UTC

Comments

There appear to be some lines in your CMakeLists.txt that I would assume are left over comments. Example:

Specify additional locations of header files
Your package locations should be listed before other locations

Can you verify?

Asked by gvdhoorn on 2019-03-08 06:31:48 UTC

Just to get you going: on Indigo, change the order of the target_link_libraries(..) statements such that ${TinyXML_LIBRARIES} comes before ${catkin_LIBRARIES}.

Asked by gvdhoorn on 2019-03-08 07:08:14 UTC

I installed various versions of tinyxml,

you might also want to make sure you still have a sane build environment after all of that.

Asked by gvdhoorn on 2019-03-08 07:09:01 UTC

Thank you for your response, yes those lines should be commented, that is a mistake I made when I was pasting it here, sorry, but in the code I have it in comments :) Your suggestion worked, I only needed to change the order, with ${TinyXML_LIBRARIES} coming first and ${catkin_LIBRARIES} coming second, it is funny, that after all the hassle I made the solution is this simple, thank you! I wouldn't solve it without your help, especially because I am still relatively new to ROS :D Thank you very much :D Hope it helps other users as well; if they encounter a similar problem :)

Asked by AaronM on 2019-03-10 14:10:57 UTC

Answers