0
$\begingroup$

I created a plugin ConditionNode to use on the behaviour tree to alter some behavior in navigation. It appears that my cmake file has an error when i run colcon build. The error is:


Starting >>> goals_and_navigation Starting >>> lab3_pkg
--- stderr: lab3_pkg
Library Name: lab3_pkg Dependencies rclcpp;behaviortree_cpp_v3;std_msgs CMake Error at /opt/ros/humble/share/ament_cmake_target_dependencies/cmake/ament_target_dependencies.cmake:42 (message):
ament_target_dependencies() the first argument must be a valid target name
Call Stack (most recent call first): CMakeLists.txt:38 (ament_target_dependencies)

gmake: *** [Makefile:267: cmake_check_build_system] Error 1

Failed <<< lab3_pkg [0.75s, exited with code 2] Aborted <<< goals_and_navigation [0.80s]

Summary: 0 packages finished [1.47s] 1 package failed: lab3_pkg 1 package aborted: goals_and_navigation 1 package had stderr output: lab3_pkg

Here is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.8)
project(lab3_pkg CXX)
# HELP ME PERES
# NOT ON GITHUB
# 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(behaviortree_cpp_v3 REQUIRED)
find_package(std_msgs REQUIRED)

include_directories(
  include
)

# as in https://github.com/ros-planning/navigation2/blob/main/nav2_behavior_tree/CMakeLists.txt
set(library_name ${PROJECT_NAME})

# Add your custom node source files NOT IN GITHUB
# set(SOURCES
#   src/DetectCone.cpp
# )

set(dependencies
  rclcpp
  behaviortree_cpp_v3
  std_msgs
)
message("Library Name: ${library_name}")
message("Dependencies ${dependencies}")


ament_target_dependencies(${library_name} # ${library_name}
  ${dependencies}
)

add_library(nav2_my_detection_plugin SHARED src/DetectCone.cpp)

# target_link_libraries(nav2_my_detection_plugin
#   ${dependencies}
# )

list(APPEND plugin_libs nav2_my_detection_plugin)



foreach(bt_plugin ${plugin_libs})
  ament_target_dependencies(${bt_plugin} ${dependencies})
  target_compile_definitions(${bt_plugin} PRIVATE BT_PLUGIN_EXPORT)
endforeach()

# Add an executable target NOT IN GITHUB
# add_executable(DetectCone ${SOURCES})

install(TARGETS ${library_name}
                ${plugin_libs}
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
)

install(DIRECTORY include/
  DESTINATION include/
)

# install(DIRECTORY test/utils/
#         DESTINATION include/${PROJECT_NAME}/utils/
# )

# install(FILES nav2_tree_nodes.xml DESTINATION share/${PROJECT_NAME})

# Link the libraries !!!!!!!!!!!!!!!!!!!!!
# ament_target_dependencies(DetectCone
#   rclcpp
#   behaviortree_cpp_v3
# )

# Install the executables/libraries !!!!!!!!!!!!!!!!!!!!!!!!!!
# install(TARGETS
#   DetectCone
#   DESTINATION lib/${PROJECT_NAME}
# )

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_export_include_directories(
  include
)

ament_export_libraries(
  ${library_name}
  ${plugin_libs}
)

ament_export_dependencies(${dependencies})

ament_package()

Anything else you need me to provide just tell me. All help is welcome :)

$\endgroup$

1 Answer 1

1
$\begingroup$

Cmake is sequential, you never actually made your library before you try to link it. Switch the order:

add_library(${library_name} SHARED src/DetectCone.cpp)

ament_target_dependencies(${library_name} # ${library_name}
  ${dependencies}
)
$\endgroup$
2
  • $\begingroup$ I had tried this before and didnt work unfortunately it throws the same error. Suposedly i set the library name on this line: set(library_name ${PROJECT_NAME}) $\endgroup$ Dec 8, 2023 at 12:16
  • $\begingroup$ Can you double check. Setting the variable for the name is not the same as creating a target with the name. If not please edit your question to include this fix and the updated error message if you'd like more help. $\endgroup$
    – Tully
    Jan 7 at 9:39

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.