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

undefined reference

asked 2014-07-01 06:45:06 -0500

ROSkinect gravatar image

updated 2014-07-03 05:20:14 -0500

Hi all I know that undefined reference error comes from the edition links during the compilation.

So what I want to do is to add an external libraries (contain method's class definition) to my package to use it in my program, so how can I do that ?

  • I'm working with ROS hydro-64bits.
  • I have a folder contains files *.so .

This is my CmakeList.txt

    cmake_minimum_required(VERSION 2.4.6)
    include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

    # Set the build type.  Options are:
    #  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage
    #  Debug          : w/ debug symbols, w/o optimization
    #  Release        : w/o debug symbols, w/ optimization
    #  RelWithDebInfo : w/ debug symbols, w/ optimization
    #  MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries
    #set(ROS_BUILD_TYPE RelWithDebInfo)

    rosbuild_init()

    #set the default path for built executables to the "bin" directory
    set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
    #set the default path for built libraries to the "lib" directory
    set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

    #uncomment if you have defined messages
    #rosbuild_genmsg()
    #uncomment if you have defined services
    #rosbuild_gensrv()

    #common commands for building c++ executables and libraries
    #rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
    #target_link_libraries(${PROJECT_NAME} another_library)
    #rosbuild_add_boost_directories()
    #rosbuild_link_boost(${PROJECT_NAME} thread)
    #rosbuild_add_executable(example examples/example.cpp)
    #target_link_libraries(example ${PROJECT_NAME})
    #target_link_libraries(MCORE /home/jros/roskinectueye/kinectueye/lib)
    #target_link_libraries(MCORE /lib)

    rosbuild_add_executable(kinectueye src/kinect_ueye.cpp)
    set(LIB_DIR ${PROJECT_SOURCE_DIR}/lib10)
    set(MY_LIBS ${LIB_DIR}/libMINTERFACE.so.0)

   target_link_libraries(kinectueye
    ${catkin_LIBRARIES} 
    ${MY_LIBS}
     )

Thank you

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2014-07-01 09:33:01 -0500

BennyRe gravatar image

updated 2014-07-03 05:27:13 -0500

List the libraries you want to link in the target_link_libraries section of your CMakeLists.txt.

Edit:

The auto generated CMakeLists.txt states the solution.

Just use target_link_libraries

Look at this example line in your CMakeLists.txt

#target_link_libraries(MCORE /home/jros/roskinectueye/kinectueye/lib)

Modify it to your needs and you should be fine.

edit flag offensive delete link more

Comments

What is the syntax? this what I need ! I have a folder named lib10 contains *.so files (Exemple of the files "libMINTERFACE.so.0")

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

If I do like that I can't generate my executable file !!

ROSkinect gravatar image ROSkinect  ( 2014-07-02 08:11:56 -0500 )edit

Sorry I'm a little bit confused. I got a notification that it works but the comment has been deleted and now theres a comment that this does not work. Does it work now or not? In the notification I saw that you are using rosbuild. Please always add the fact that you are using rosbuild.

BennyRe gravatar image BennyRe  ( 2014-07-02 09:50:42 -0500 )edit

With rosbuild my answer will not work.

BennyRe gravatar image BennyRe  ( 2014-07-02 09:51:02 -0500 )edit

I thought that it worked because when I compile I don't get any error but it's generate another error that I can't get the executable file !! no I'm not using rosbuild

ROSkinect gravatar image ROSkinect  ( 2014-07-02 11:56:11 -0500 )edit

Did you replace 'your_node' with the name of your node and are your libs also in a directory called 'lib'?

BennyRe gravatar image BennyRe  ( 2014-07-03 01:02:07 -0500 )edit

Yes I did, as I told you I can compile it but I can't get my executable file ! "so I can't really know If it works or not"

ROSkinect gravatar image ROSkinect  ( 2014-07-03 02:33:26 -0500 )edit

Please post the entire CMakeLists.txt file. It is very difficult to help without knowing what you already know. :-)

McMurdo gravatar image McMurdo  ( 2014-07-03 04:53:13 -0500 )edit
0

answered 2014-07-01 08:24:39 -0500

McMurdo gravatar image

Please add

link_directories(<location of your directory with the shared libs>)

to your CMakeLists.txt.

edit flag offensive delete link more

Comments

I tried that but it doesn't work (I add this link_directories(/home/../../lib/lib64) to CMakeLists)

ROSkinect gravatar image ROSkinect  ( 2014-07-01 08:56:00 -0500 )edit

And after that you should link those libraries to the executable. target_link_libraries(name_of_executable name_of_library), If the library is called "libsuperb.so" and the executable is called "amazing_node" then the entry should be target_link_libraries(amazing_node superb)

McMurdo gravatar image McMurdo  ( 2014-07-01 09:50:17 -0500 )edit

If you use catkin, there might already be a line that says, target_link_libraries(amazing_node ${catkin_LIBRARIES}) ===> change this to ===> target_link_libraries(amazing_node ${catkin_LIBRARIES} superb)

McMurdo gravatar image McMurdo  ( 2014-07-01 09:53:09 -0500 )edit

I found the solution thank you McMurdo

ROSkinect gravatar image ROSkinect  ( 2014-07-03 05:59:30 -0500 )edit

Could you please explain how you solved it. Others can refer to it if they have the same issue. Thanks!

McMurdo gravatar image McMurdo  ( 2014-07-04 05:43:20 -0500 )edit

From your CMakeLists.txt -> You are indeed using rosbuild and not catkin. And I am gussing that the error was that you didn't add "rosbuild_add_executable()" to your CMakeLists.txt

McMurdo gravatar image McMurdo  ( 2014-07-04 05:45:04 -0500 )edit

set(MY_LIBS1 ${LIB_DIR} /home/jros/MIXEDVISION_PO/lib64/libgsl.so.0.16.0) target_link_libraries(kinectueye ${catkin_LIBRARIES} ${MY_LIBS} ${MY_LIBS1} ) I did that for all libraries that I have I had rosbuild_add_executable before

ROSkinect gravatar image ROSkinect  ( 2014-07-04 06:04:18 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2014-07-01 06:45:06 -0500

Seen: 386 times

Last updated: Jul 03 '14