ROS2 Foxy fail to link kdl_parser
I followed the standard procedure to install ROS2 Foxy debian on Ubuntu20.04. I tried to build a package with kdl_parser. However, I got a Cmake error:
CMake Error at CMakeLists.txt:24 (add_executable): Target "robotKinematicsNode" links to target "urdf::urdf" 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. make: * [Makefile:266: cmake_check_build_system] Error 1
The following is my CMakeList.txt file:
cmake_minimum_required(VERSION 3.5)
project(robot_kinematics)
# 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(rclcpp REQUIRED)
find_package(kdl_parser REQUIRED)
find_package(orocos_kdl REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(tf2_kdl REQUIRED)
find_package(tf2_ros REQUIRED)
## Add executable
add_executable(robotKinematicsNode src/robot_kinematics.cpp)
ament_target_dependencies(robotKinematicsNode rclcpp kdl_parser orocos_kdl sensor_msgs geometry_msgs tf2_kdl tf2_ros)
install(TARGETS
robotKinematicsNode
DESTINATION lib/${PROJECT_NAME})
ament_package()
The following is the package.xml
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>robot_kinematics</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="xxx@todo.todo">xxx</maintainer>
<license>TODO: License declaration</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<depend>rclcpp</depend>
<depend>kdl_parser</depend>
<depend>orocos_kdl</depend>
<depend>sensor_msgs</depend>
<depend>tf2_kdl</depend>
<depend>tf2_ros</depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
If I removed "kdl_parser" from the ament_target_dependencies in the CMakeList, the package can be built successfully. I wondered why it causeed the Cmake fail. It would be nice to hear any answer to resolve the issue. Thank you!