Ask Your Question
0

Still cannot include library to package from another package

asked 2018-01-31 04:19:25 -0500

Megacephalo gravatar image

updated 2018-01-31 04:24:03 -0500

Hi all,

I want to use several libraries created in one package, let say package A, into package B. Both packages' bareboned CMakeLists look like this:

A : The package in which my custom libraries reside:

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(A)

catkin_package(
  INCLUDE_DIRS include
  LIBRARIES killer_utils_lib
             haha_lib
  CATKIN_DEPENDS ... <-- just a simplification
  DEPENDS ...
}

include_directories(
  include
  ${catkin_INCLUDE_DIRS}
)

add_library(killer_utils_lib src/killer_utils.cpp )
add_library(haha_lib src/haha.cpp)

target_link_libraries(killer_utils_lib 
  ${catkin_LIBRARIES}
)
target_link_libraries(haha_lib
  ${catkin_LIBRARIES}
)

install(TARGETS
  killer_utils_lib
  haha_lib
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
  PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(DIRECTORY include/${PROJECT_NAME}/
  DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
  FILES_MATCHING PATTERN "*.h"
  PATTERN ".svn" EXCLUDE
)

B : The package to which I want to import my custom libraries

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(B)

find_package(catkin REQUIRED COMPONENTS
  ...
  killer_utils_lib
  haha_lib
)

catkin_package(
  INCLUDE_DIRS include
  ...
)

include_directories(include)
include_directories(
  ${catkin_INCLUDE_DIRS}
  ${killer_utils_lib_INCLUDE_DIRS}
  ${haha_lib_INCLUDE_DIRS}
)

add_executable(example src/example.cpp)
target_link_libraries(example ${catkin_LIBRARIES} killer_utils_lib haha_lib)

package.xml in B

<build_depend>killer_utils_lib</build_depend>
<build_depend>haha_lib</build_depend>

If I put these two files to compile, The following error messages will pop up:

CMake Warning at /opt/ros/kinetic/share/catkin/cmake/catkinConfig.cmake:76 (find_package):
  Could not find a package configuration file provided by "killers_utils_lib"
  with any of the following names:

    killer_utils_libConfig.cmake
    killer_utils_lib-config.cmake

  Add the installation prefix of "killer_utils_lib" to CMAKE_PREFIX_PATH or
  set "killer_utils_lib_DIR" to a directory containing one of the above
  files.  If "killer_utils_lib" provides a separate development package or
  SDK, be sure it has been installed.
Call Stack (most recent call first):
  task/decision_tasks/CMakeLists.txt:7 (find_package)


-- Could not find the required component 'killer_utils_lib'. The following CMake error indicates that you either need to install the package with the same name or change your environment so that it can be found.
CMake Error at /opt/ros/kinetic/share/catkin/cmake/catkinConfig.cmake:83 (find_package):
  Could not find a package configuration file provided by "killer_utils_lib"
  with any of the following names:

    killer_utils_libConfig.cmake
    killer_utils_lib-config.cmake

  Add the installation prefix of "killer_utils_lib" to CMAKE_PREFIX_PATH or
  set "killer_utils_lib_DIR" to a directory containing one of the above
  files.  If "killer_utils_lib" provides a separate development package or
  SDK, be sure it has been installed.

My question is, I've followed the steps as given in this ROS Answer article, why do my custom shared libraries killer_utils_lib and haha_lib still not be seen by other packages?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2018-01-31 04:53:30 -0500

mgruhler gravatar image

updated 2018-01-31 04:55:20 -0500

Because the cmake config gets generated for the package and not for each lib seperately.

So you need to find_package your package A. The environment variables (e.g. A_LIBRARIES) are then populated with the libraries inside the package.

To cite the question you link to:

• have a build_depend on my_package in its package.xml

• have called find_package(my_package REQUIRED) in its CMakeLists.txt

edit flag offensive delete link more

Comments

Thank you @mig!! Now I understand better how this building mechanism works!! Now the libraries can be imported into another package!

Megacephalo gravatar imageMegacephalo ( 2018-02-01 03:27:32 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

4 followers

Stats

Asked: 2018-01-31 04:19:25 -0500

Seen: 1,583 times

Last updated: Jan 31 '18