catkin build can't find shared library from a dependent package
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
)
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.