ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Colcon Build Error with ROS2 Eloquent and Libtorch

asked 2020-05-17 14:09:13 -0500

mequi gravatar image

updated 2020-05-17 15:23:21 -0500

Hello. I am trying to build my package with colcon and it has stoped building correctly over the past day and I am not sure why. I have attached the error that colcon emits below. Reading through it signals to me that there is an issue with the linker but I cant figure out how to solve it. I have also attached my CMakeLists for the package as well so you can check that out. The strange part is that this worked a couple of days ago and on multiple versions of my package. Now it does not work on any past or present version and on either ARM or X86 machines (all running ROS2 eloquent + Ubuntu 18.04). Any help is greatly appreciated.

CMakeLists:

cmake_minimum_required(VERSION 3.5)
project(br-detection)

# 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()

list(APPEND CMAKE_PREFIX_PATH "~/.local/lib/python3.6/site-packages/torch")

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(ament_index_cpp REQUIRED)
find_package(rclpy REQUIRED)
find_package(rclcpp REQUIRED)
find_package(ament_cmake_python REQUIRED)
find_package(OpenCV 4.2 REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(message_filters REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(image_geometry REQUIRED)
find_package(OpenMP)
find_package(Torch REQUIRED)

 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")

add_executable(br-human-tracking src/pose_tracker.cpp src/pose_tracker_helpers.cpp src/tracking.cpp)

target_link_libraries(br-human-tracking "${TORCH_LIBRARIES}")
target_link_libraries(br-human-tracking OpenMP::OpenMP_CXX)
set_property(TARGET br-human-tracking PROPERTY CXX_STANDARD 14)

target_include_directories(br-human-tracking PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/br-detection>
        $<INSTALL_INTERFACE:include/br-detection>)

target_include_directories(br-human-tracking PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/br-detection>
        $<INSTALL_INTERFACE:include/br-detection>)

ament_target_dependencies(
        br-human-tracking
        rclcpp
        message_filters
        sensor_msgs
        cv_bridge
        OpenCV
        image_geometry
        tf2
        tf2_ros
        ament_index_cpp
        Eigen3
        Torch
)

install(TARGETS br-human-tracking
        EXPORT export_${PROJECT_NAME}
        DESTINATION lib/${PROJECT_NAME})

install(
        DIRECTORY models
        DESTINATION share/${PROJECT_NAME}/
)

install(DIRECTORY launch
        DESTINATION share/${PROJECT_NAME}/
)

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()

Error:

CMakeFiles/br-human-tracking.dir/src/pose_tracker.cpp.o: In function `PeopleTracker::PeopleTracker()':
pose_tracker.cpp:(.text+0xa94): undefined reference to `rclcpp::Node::Node(std::string const&, rclcpp::NodeOptions const&)'
pose_tracker.cpp:(.text+0x1421): undefined reference to `rclcpp::Node::get_parameter(std::string const&) const'
pose_tracker.cpp:(.text+0x1562): undefined reference to `rclcpp::Node::get_parameter(std::string const&) const'
pose_tracker.cpp:(.text+0x1571): undefined reference to `rclcpp::Parameter::as_string() const'
pose_tracker.cpp:(.text+0x198a): undefined reference to `ament_index_cpp::get_package_share_directory(std::string const&)'
pose_tracker.cpp:(.text+0x1b87): undefined reference to `rclcpp::get_c_string(std::string const&)'
pose_tracker.cpp:(.text+0x1e8c): undefined reference to `ament_index_cpp::get_package_share_directory(std::string const&)'
pose_tracker.cpp:(.text+0x2089): undefined reference to `rclcpp::get_c_string(std::string const&)'
CMakeFiles/br-human-tracking.dir/src/pose_tracker.cpp.o: In function `PeopleTracker::stereo_cb(std::shared_ptr<sensor_msgs::msg::Image_<std::allocator<void> > > const&, std::shared_ptr<sensor_msgs ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-05-21 13:48:18 -0500

mequi gravatar image

Ok, so I figured it out. Apparently the libtorch binaries installed by pip are compiled pre GCC 5.0 and so have ABI = 0 which messes with the linking of other C++ libraries. The cxx11 ABI (ABI = 1) version of libtorch downloadable from here https://pytorch.org/ fixed the problem. I am not sure exactly why the python binaries are still Pre-cxx11 ABI for X86 since on the Jetson Nano the ones provided by Nvidia are cxx11 ABI and hence worked fine and led partly to all this confusion.

edit flag offensive delete link more

Comments

Thanks for the solution. Saved my day !!!

Santosh Balaji gravatar image Santosh Balaji  ( 2023-06-16 05:21:05 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2020-05-17 14:09:13 -0500

Seen: 1,622 times

Last updated: May 21 '20