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

undefined reference to `urdf::Model::initFIle()'

asked 2014-06-30 22:06:10 -0500

cyberguy42 gravatar image

I am attempting to compile a cpp file that will read joint limits from a urdf. The lines of code at issue are:

urdf::Model robotModel;

robotModel.initFile("path/to/file");

I get the following error: undefined reference to `urdf::Model::initFile(std::basic_string<char, std::char_traits<char="">, std::allocator<char> > const&)'

Commenting out 'robotModel.initFile(...)' eliminates the error, but defeats the purpose of the program.

The error appears while linking. It appears that I am passing in the proper argument- it seems to match the documentation. In my CMakeLists, I have 'link_directories(/opt/ros/hydro/lib/)', which I have confirmed contains libkdl_parser.so and liburdfdom_model.so. The same type of error occurs if I use .initString(). What am I missing?

edit retag flag offensive close merge delete

Comments

Please post your CMakeLists.txt

BennyRe gravatar image BennyRe  ( 2014-07-01 07:49:04 -0500 )edit

The problem was in my CMakeLists.txt. Thank you for your comment.

cyberguy42 gravatar image cyberguy42  ( 2014-07-01 08:57:03 -0500 )edit

Could you please post your CMakeLists? I have the same problem

Andromeda gravatar image Andromeda  ( 2014-08-28 15:47:36 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-07-01 08:55:23 -0500

cyberguy42 gravatar image

updated 2014-07-01 09:30:03 -0500

Updated Answer

Though my original solution was accurate, my explanation that the problem was Swig-related was incorrect: all things Swig are handled elsewhere. The problem was that I did not include 'urdf' in the variable MY_ADDED_LIBS, which is used by target_link_libraries. Adding it resolved the linking issue and I can load joint limits from the urdf just fine.

My corrected CMakeLists.txt is below:

cmake_minimum_required(VERSION 2.8.3)
project(base-kdl)

set(BASE_FILE_NAME base-kinematics)

include_directories(/usr/include/eigen3)
include_directories(/usr/include/boost/)
include_directories(/opt/ros/hydro/include/)
include_directories(/opt/ros/hydro/include/kdl)

FIND_PACKAGE(JNI)
if (NOT JAVA_INCLUDE_PATH)
  message(WARNING "JNI has not been found.")
endif()

include_directories(${JAVA_INCLUDE_PATH})
include_directories(${JAVA_INCLUDE_PATH2})

link_directories(/opt/ros/hydro/lib/)

set(CMAKE_CXX_FLAGS -Wl,-z,defs)

set(MY_ADDED_LIBS orocos-kdl;kdl_parser;urdf)

add_library(swig_kdl SHARED  base-kinematics_wrap.cpp base-kinematics.cpp)
target_link_libraries(swig_kdl ${MY_ADDED_LIBS})
edit flag offensive delete link more

Comments

can you post what did you add exactly to your CMakeLists.txt !?

ROSkinect gravatar image ROSkinect  ( 2014-07-01 08:59:47 -0500 )edit

OK can you explain to me in the last line what is "swig_kdl" and "MY_ADDED_LIBS" because I need that too but I don't know what to put in swig_kdl and MY_ADDED_LIBS places ?

ROSkinect gravatar image ROSkinect  ( 2014-07-01 09:42:08 -0500 )edit

swig_kdl is the name of the library I am building, just put in the name of yours. MY_ADDED_LIBS should contain the libraries you use. Hope that helps. If not, you may want to create your own question so you can ask the community for help with your specific question.

cyberguy42 gravatar image cyberguy42  ( 2014-07-01 10:47:12 -0500 )edit

Thank you it works now: what I did is simply add that: rosbuild_add_library(${PROJECT_NAME} /lib)

ROSkinect gravatar image ROSkinect  ( 2014-07-02 04:04:23 -0500 )edit

I still have the same problem. I put: set( MY_ADDED_LIBS kdl_parser;urdf ) and then target_link_libraries( state_publisher ${MY_ADDED_LIBS} ) but I get again: target_link_libraries( state_publisher ${MY_ADDED_LIBS} ) Please could you post an example of a working CMakeLists.txt?

Andromeda gravatar image Andromeda  ( 2014-08-15 12:37:23 -0500 )edit
1

answered 2019-03-15 14:35:31 -0500

mwenger gravatar image

I ran into the same issue when working through the urdf tutorials. I spent significant amount of time tracking down the issue only to realize the way to fix it is add urdf to find_package() in the CMakeList.txt file.

find_package(catkin REQUIRED COMPONENTS
    roscpp
    rospy
    std_msgs
    urdf <-- Added this and it fixed the issue
)
edit flag offensive delete link more

Comments

The above fixed my error too! Thank You!

Trayach_ gravatar image Trayach_  ( 2021-12-26 00:41:36 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-06-30 22:06:10 -0500

Seen: 1,619 times

Last updated: Jul 01 '14