Include library from another package
EDIT
i manege to solve it by adding the line to my ur_interface CMakeListt:
ament_export_dependencies(ur_rtde tf2)
now i dont need to use find_package in the test_clasess CMakeListt
-----------------------------------
Hello everyone. i am using ros2 foxy.
I have two packages, package A and package B. Package B uses package A, and package A uses some installed libraries (tf2,ur_rtde). When I import package A in package B and try to colcon build it, I get the following error:
--- stderr: test_clasess
CMake Error at CMakeLists.txt:26 (add_executable):
Target "test_clsass" links to target "ur_rtde::rtde" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
CMake Error at CMakeLists.txt:26 (add_executable):
Target "test_clsass" links to target "tf2::tf2" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
CMake Generate step failed. Build files cannot be regenerated correctly.
whan i add to package B CMakeLists :
find_package(ur_rtde REQUIRED)
find_package(tf2 REQUIRED)
its work fine. t seems weird to me that I need to add find_package in package B, which is package A dependences. did i miss something? or its the only way to import library from another package?
package A CMakeLists:
cmake_minimum_required(VERSION 3.5)
project(ur_interface)
# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
include_directories(include)
# find dependencies
find_package(ament_cmake REQUIRED)
find_package(ur_rtde REQUIRED)
find_package(tf2 REQUIRED)
# include/ur_interface/UrInterface.h
add_library(ur_interface src/UrInterface.cpp)
target_include_directories(ur_interface PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_link_libraries(ur_interface ur_rtde::rtde)
ament_target_dependencies(ur_interface tf2)
ament_export_targets(ur_interface HAS_LIBRARY_TARGET)
ament_export_include_directories(include)
install(
DIRECTORY include/ur_interface
DESTINATION include
)
install(
TARGETS ur_interface
EXPORT ur_interface
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
#install(TARGETS ur_interface
# DESTINATION lib/${PROJECT_NAME})
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
ament_package()
package B CMakeLists:
cmake_minimum_required(VERSION 3.5)
project(test_clasess)
# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# find dependencies
find_package(ament_cmake REQUIRED)
find_package(ur_interface REQUIRED)
add_executable(test_clsass src/test_clsass.cpp)
target_include_directories(test_clsass PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
ament_target_dependencies(test_clsass
"ur_interface"
)
install(TARGETS test_clsass
DESTINATION lib/${PROJECT_NAME})
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif()
ament_package()
tf2_ros
package as well.target_link_libraries(ur_interface PRIVATE ur_rtde::rtde)
tanks for the fast replay.
1.Where should i including tf2_ros? in the CMakeLists of Package A of B? add it as a package?
i get the error:
but ament_target_dependencies except only package names.