0
$\begingroup$

Rosanswers logo

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?


Originally posted by Megacephalo on ROS Answers with karma: 106 on 2018-01-31

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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


Originally posted by mgruhler with karma: 12390 on 2018-01-31

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by Megacephalo on 2018-02-01:
Thank you @mig!! Now I understand better how this building mechanism works!! Now the libraries can be imported into another package!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.