GTest with ROS2 - colcon package build fails

Hi The Construct Team,

I am learning GTest Framework for ROS2 course. I am currently on Unit 3 - Test Subscribers and Publishers using Google Test.

In section 3.1, “Build and install”:
colcon build --packages-select distance_control - this command fails.

Expected Output: (as specified in the notes)

Starting >>> distance_control
Finished <<< distance_control [21.0s]
Summary: 1 package finished [21.6s]

(Current) Actual Output:

Starting >>> distance_control
Failed   <<< distance_control [14.2s, exited with code 2]

Summary: 0 packages finished [14.3s]
  1 package failed: distance_control

Copy-pasted all the provided codes from the notebook “as-is” without any modification, but the build fails. Also verified package and folder structures - they are fine.

Please help.

Thanks,
Girish

EDIT: Rebuilding with colcon build --packages-select distance_control --event-handlers console_cohesion+ produces the following message:

Starting >>> distance_control
--- output: distance_control
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found ament_cmake: 1.1.5 (/opt/ros/galactic/share/ament_cmake/cmake)
-- Found PythonInterp: /usr/bin/python3 (found suitable version "3.8.10", minimum required is "3")
-- Using PYTHON_EXECUTABLE: /usr/bin/python3
-- Found rclcpp: 9.2.0 (/opt/ros/galactic/share/rclcpp/cmake)
-- Using all available rosidl_typesupport_c: rosidl_typesupport_fastrtps_c;rosidl_typesupport_introspection_c
-- Found rosidl_adapter: 2.2.1 (/opt/ros/galactic/share/rosidl_adapter/cmake)
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "1.1.1f")
-- Found FastRTPS: /opt/ros/galactic/include
-- Using all available rosidl_typesupport_cpp: rosidl_typesupport_fastrtps_cpp;rosidl_typesupport_introspection_cpp
-- Found rmw_implementation_cmake: 3.3.1 (/opt/ros/galactic/share/rmw_implementation_cmake/cmake)
-- Found rmw_cyclonedds_cpp: 0.22.4 (/opt/ros/galactic/share/rmw_cyclonedds_cpp/cmake)
-- Using RMW implementation 'rmw_cyclonedds_cpp' as default
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/ros2_ws/build/distance_control
Scanning dependencies of target distance_control_lib
[ 25%] Building CXX object CMakeFiles/distance_control_lib.dir/src/distance_control.cpp.o
[ 50%] Linking CXX static library libdistance_control_lib.a
[ 50%] Built target distance_control_lib
Scanning dependencies of target main
[ 75%] Building CXX object CMakeFiles/main.dir/src/main.cpp.o
---
Failed   <<< distance_control [13.3s, exited with code 2]

Summary: 0 packages finished [13.4s]
  1 package failed: distance_control

Hi The Construct Team,

This problem is solved.

The following command indicated that the problem was in the main.cpp file.
colcon build --packages-select distance_control --event-handlers console_cohesion+

So, I checked the main.cpp file and found that there was an error:
The first include line had wrong quote symbols.

#include “distance_control/distance_control_header.h”

After replacing the quotes as shown in following line, it got fixed.

#include "distance_control/distance_control_header.h"

Now the Current Output is same as Expected Output !

Regards,
Girish

Fixed this in the notebooks. Thanks for the feedback @girishkumar.kannan

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.