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

catkin build can't find shared library from a dependent package

asked 2015-05-28 02:51:33 -0500

Nap gravatar image

updated 2015-05-28 04:29:21 -0500

I've Just started using catkin_tools, and catkin build. It seems to require more precicely specified CMakeLists.txt files, and this is causing my grief at the moment.

I have package_A that depends on package_B's shared library. They are both within the one workspace.
When I catkin build package_A, package_B is built first, and it's shared library is placed in devel/lib. However, when package_A is linked, I get an error saying it can't find the library generated by package_B.

In package_A's CMakeLists.txt:
- I have used find_package (package_B),
- I have included package_B in the catkin_package( CATKIN_DEPENDS ) section,
- I have package_B mentioned in the target_link_libraries for the package_A target.

In package_B's CMakeLists.txt:
- I have package_B mentioned in catkin_package ( LIBRARIES ) section.

If I add a line link_directories(${CATKIN_DEVEL_PREFIX}/lib}) then it works fine. However, this doesn't look like the proper solution to me.

Any suggestions on what I'm missing / doing wrong?

Cheers,
Nap

Here are the CMakeLists.txt files from the packages in full:

Package_A:

cmake_minimum_required(VERSION 2.8.3)
project(whiteboard_test)

find_package(catkin REQUIRED COMPONENTS gusimplewhiteboard)

catkin_package(
  INCLUDE_DIRS include
  CATKIN_DEPENDS gusimplewhiteboard
)

set(CMAKE_C_FLAGS "-std=c99")
set(CMAKE_CXX_FLAGS "-std=c++11 -DWHITEBOARD_POSTER_STRING_CONVERSION=1")
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-rpath -Wl,${CMAKE_INSTALL_PREFIX}/lib")

include_directories(
    include
    ${gusimplewhiteboard_INCLUDE_DIRS}
)

###  THIS LINE IS REQUIRED TO FIND THE LIBRARY????? ###
link_directories(${CATKIN_DEVEL_PREFIX}/lib)

add_executable(whiteboard_test
    src/whiteboard_test.cpp
)
target_link_libraries(whiteboard_test
    gusimplewhiteboard
    ${CMAKE_DL_LIBS}
    ${LIBDISPATCH_LIBRARIES}
    ${CMAKE_THREAD_LIBS_INIT}
    dispatch
)
add_dependencies(whiteboard_test
    gusimplewhiteboard
)

SOLVED BY:

Removing:

###  THIS LINE IS REQUIRED TO FIND THE LIBRARY????? ###
link_directories(${CATKIN_DEVEL_PREFIX}/lib)

and changing target_link_libraries statement to:

target_link_libraries(whiteboard_test
    ${catkin_LIBRARIES}
    ${CMAKE_DL_LIBS}
    ${LIBDISPATCH_LIBRARIES}
    ${CMAKE_THREAD_LIBS_INIT}
    dispatch
)
edit retag flag offensive close merge delete

Comments

It would probably help (or at least, help me) if you include the actual snippets from your CMakeLists.txt that you're using, instead of an abstracted version. Not the entire text, just the bits that are important.

gvdhoorn gravatar image gvdhoorn  ( 2015-05-28 03:53:24 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2015-05-28 04:06:16 -0500

Wolf gravatar image

You do not need:

  • I have package_B mentioned in the target_link_libraries for the package_A target.

and

add a line link_directories(${CATKIN_DEVEL_PREFIX}/lib})

If you add a lib created in a package in the same package's CMakeLists.txt catkin_package ( LIBRARIES ) section as you did here

  • I have package_B mentioned in catkin_package ( LIBRARIES ) section.

and find_package the package in a depending package as you did here

  • I have used find_package (package_B),

, the lib will automatically linked against targets in all depending packages.

Hint:

For this to work you need, as for all targets using ros functions, to link against catkin_LIBRARIES

target_link_libraries( your_target ${catkin_LIBRARIES} )
edit flag offensive delete link more

Comments

1

thanks Wolf, I did as you suggested and it worked.
I had to add ${catkin_LIBRARIES}AND remove the reference to the shared library (gusimplewhiteboard in my case) from the target_link_libraries statement.

Nap gravatar image Nap  ( 2015-05-28 04:21:49 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2015-05-28 02:51:33 -0500

Seen: 4,731 times

Last updated: May 28 '15