osrf / rmf_core

Provides the centralized functions of RMF: scheduling, etc.
Apache License 2.0
102 stars 41 forks source link

build fail for custom package #280

Closed txlei closed 3 years ago

txlei commented 3 years ago

Hi, i have problem with linking the rmf libraries. been on it for some time before posting this. Could you advise please.

Using ament_target_dependencies, produced this error but I've check that /install/rmf_traffic_ros2/lib/schedule exist.

CMake Error at CMakeLists.txt:68 (add_executable):
  Target "su_detection" links to target
  "rmf_traffic_ros2::rmf_traffic_schedule" 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:68 (add_executable):
  Target "su_detection" links to target
  "rmf_traffic_ros2::rmf_traffic_blockade" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?

without using ament_target_dependencies though ${rmf_traffic_ros2_LIBRARIES} is specified, below error generated

...
fatal error: rmf_traffic_ros2/schedule/Writer.hpp: No such file or directory
    3 | #include <rmf_traffic_ros2/schedule/Writer.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

cmakelist.txt as follows

cmake_minimum_required(VERSION 3.5)
project(su_traffic_participant)
set(CMAKE_EXPORT_COMPILE_COMMANDS on)

# 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(geometry_msgs REQUIRED)
find_package(Eigen3 REQUIRED)
include(GNUInstallDirs)

set(dep_pkgs
  rclcpp
  rmf_utils
  rmf_traffic
  rmf_traffic_ros2
  su_msgs
  std_msgs
)
foreach(pkg ${dep_pkgs})
  find_package(${pkg} REQUIRED)
endforeach()

file(GLOB_RECURSE su_traffic_participant_srcs "src/*.cpp")

add_library(su_traffic_participant SHARED
  ${su_traffic_participant_srcs}
)

target_link_libraries(su_traffic_participant
  PUBLIC
    rmf_traffic_ros2::rmf_traffic_ros2
    rmf_traffic::rmf_traffic
    su_msgs
    ${rmf_traffic_ros2_LIBRARIES}
    ${rclcpp_LIBRARIES}
)

target_include_directories(su_traffic_participant
  PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
    $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
    ${EIGEN3_INCLUDE_DIRS}
    ${rmf_traffic_ros2_INCLUDE_DIRS}
    ${rclcpp_INCLUDE_DIRS}
)

#===============================================================================

add_executable(listener src/detection_subscriber.cpp)
ament_target_dependencies(listener rclcpp su_msgs)

#===============================================================================

add_executable(su_detection
  src/main.cpp
  src/DetectionNode.cpp
)
ament_target_dependencies(su_detection 
  rclcpp
  rmf_traffic_ros2
)

#===============================================================================

install(
  TARGETS
    listener
    su_detection
  EXPORT su_detection
  RUNTIME DESTINATION lib/${PROJECT_NAME}
  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

#===============================================================================

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

ament_package()
mxgrey commented 3 years ago

I suspect that getting rid of ${rmf_traffic_ros2_LIBRARIES} from target_link_libraries should fix this error.

The targets that it says are missing are executable targets, not library targets. I suspect those targets must be inadvertently getting lumped into rmf_traffic_ros2_LIBRARIES by ament. I'll take a look at the rmf_traffic_ros2 cmake script to see if we can fix that upstream.

txlei commented 3 years ago

removed ${rmf_traffic_ros2_LIBRARIES} but still producing same error.

mxgrey commented 3 years ago

Do these errors happen if you remove uses of ament_target_dependencies?

txlei commented 3 years ago

yeap. but as mentioned in the first post, there would be other build errors.

...
fatal error: rmf_traffic_ros2/schedule/Writer.hpp: No such file or directory
    3 | #include <rmf_traffic_ros2/schedule/Writer.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mxgrey commented 3 years ago

Which of your targets is getting that missing include error? Whichever one it is, you probably need to add a

target_link_libraries(<your_target_name>
  PUBLIC
    rmf_traffic_ros2::rmf_traffic_ros2
)

It looks like you're creating a bunch of executable targets that are only using ament_target_dependencies to link libraries to them. If ament_target_dependencies is removed, then they won't have any dependencies linked.

txlei commented 3 years ago

@mxgrey thanks, changing to the right target solved the problem.