79619483

Date: 2025-05-13 10:34:38
Score: 3.5
Natty:
Report link

The same trick worked for me, but I have now a more complex case now.

What if I had a second catkin package that depends on the one using the imported library, and I want this second package to use the library?

Because I can't install an imported library with CMake, I'm forced to install it as a file, e.g.:

First catkin package

cmake_minimum_required(VERSION 3.0.2)
project(first_ros_project)
find_package(catkin REQUIRED)
catkin_package(INCLUDE_DIRS include
               LIBRARIES ${PROJECT_NAME})
add_library(${PROJECT_NAME} SHARED IMPORTED)
set_target_properties(${PROJECT_NAME} PROPERTIES
        IMPORTED_LOCATION ${LIB_PATH}) # Assume this variable is filled in
install(FILES ${LIB_PATH}
        DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})

Second catkin package:

cmake_minimum_required(VERSION 3.0.2)
project(second_ros_project)
find_package(catkin REQUIRED COMPONENTS first_ros_project)
add_executable(second_node src/second_node.cpp)
target_link_libraries(second_node ${catkin_LIBRARIES})

Compiling the second package gives me an error like this:

 Project 'second_ros_project' tried to find library 'first_ros_project'.
  The library is neither a target nor built/installed properly.  Did you
  compile project 'first_ros_project'? Did you find_package() it before the
  subdirectory containing its code is included?

This is because the target was not installed, just the library as a file.

Following this link it appears the only way is to make a custom Find*.cmake but I'm unsure how to do this correctly for a catkin package.

Reasons:
  • Blacklisted phrase (1): this link
  • Whitelisted phrase (-1): worked for me
  • RegEx Blacklisted phrase (3): Did you find
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (0.5):
Posted by: mcamurri