Hi The Construct Team,
I am currently working on the Course Project [rosject] for ROS2 Basics in 5 Days - Python.
I created my custom interfaces package but colcon build ...
fails.
I tried creating the exact same package in course environment and it works fine. There seems to be some issue with ROSDS environment, I believe, seems more like dependency requirement.
TL;DR / Summary: It seems the ROSDS environment is missing pthreads
in path /usr/bin/ld
as stated in last part of CMakeError.log
file
Output of colcon build --packages-select my_interfaces --event-handlers console_cohesion+
:
user:~/ros2_ws$ colcon build --packages-select my_interfaces --event-handlers console_cohesion+
Starting >>> my_interfaces
--- output: my_interfaces
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.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: 0.9.9 (/opt/ros/foxy/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: 2.4.0 (/opt/ros/foxy/share/rclcpp/cmake)
-- Using all available rosidl_typesupport_c: rosidl_typesupport_fastrtps_c;rosidl_typesupport_introspection_c
-- Found rosidl_adapter: 1.2.1 (/opt/ros/foxy/share/rosidl_adapter/cmake)
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "1.1.1f")
-- Found FastRTPS: /opt/ros/foxy/include
-- Using all available rosidl_typesupport_cpp: rosidl_typesupport_fastrtps_cpp;rosidl_typesupport_introspection_cpp
-- Found rmw_implementation_cmake: 1.0.3 (/opt/ros/foxy/share/rmw_implementation_cmake/cmake)
-- Using RMW implementation 'rmw_fastrtps_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
-- Found geometry_msgs: 2.0.4 (/opt/ros/foxy/share/geometry_msgs/cmake)
-- Found action_msgs: 1.0.0 (/opt/ros/foxy/share/action_msgs/cmake)
-- Found rosidl_default_generators: 1.0.1 (/opt/ros/foxy/share/rosidl_default_generators/cmake)
-- Found PythonInterp: /usr/bin/python3 (found version "3.8.10")
-- Configuring incomplete, errors occurred!
See also "/home/user/ros2_ws/build/my_interfaces/CMakeFiles/CMakeOutput.log".
See also "/home/user/ros2_ws/build/my_interfaces/CMakeFiles/CMakeError.log".
---
Failed <<< my_interfaces [2.60s, exited with code 1]
Summary: 0 packages finished [2.75s]
1 package failed: my_interfaces
Contents of CMakeError.log
file:
Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: /home/user/ros2_ws/build/my_interfaces/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_d6686/fast && /usr/bin/make -f CMakeFiles/cmTC_d6686.dir/build.make CMakeFiles/cmTC_d6686.dir/build
make[1]: Entering directory '/home/user/ros2_ws/build/my_interfaces/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_d6686.dir/src.c.o
/usr/bin/cc -DCMAKE_HAVE_LIBC_PTHREAD -o CMakeFiles/cmTC_d6686.dir/src.c.o -c /home/user/ros2_ws/build/my_interfaces/CMakeFiles/CMakeTmp/src.c
Linking C executable cmTC_d6686
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_d6686.dir/link.txt --verbose=1
/usr/bin/cc -DCMAKE_HAVE_LIBC_PTHREAD CMakeFiles/cmTC_d6686.dir/src.c.o -o cmTC_d6686
/usr/bin/ld: CMakeFiles/cmTC_d6686.dir/src.c.o: in function `main':
src.c:(.text+0x46): undefined reference to `pthread_create'
/usr/bin/ld: src.c:(.text+0x52): undefined reference to `pthread_detach'
/usr/bin/ld: src.c:(.text+0x63): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_d6686.dir/build.make:87: cmTC_d6686] Error 1
make[1]: Leaving directory '/home/user/ros2_ws/build/my_interfaces/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_d6686/fast] Error 2
Source file was:
#include <pthread.h>
void* test_func(void* data)
{
return data;
}
int main(void)
{
pthread_t thread;
pthread_create(&thread, NULL, test_func, NULL);
pthread_detach(thread);
pthread_join(thread, NULL);
pthread_atfork(NULL, NULL, NULL);
pthread_exit(NULL);
return 0;
}
Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /home/user/ros2_ws/build/my_interfaces/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_d2b17/fast && /usr/bin/make -f CMakeFiles/cmTC_d2b17.dir/build.make CMakeFiles/cmTC_d2b17.dir/build
make[1]: Entering directory '/home/user/ros2_ws/build/my_interfaces/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_d2b17.dir/CheckFunctionExists.c.o
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTC_d2b17.dir/CheckFunctionExists.c.o -c /usr/share/cmake-3.16/Modules/CheckFunctionExists.c
Linking C executable cmTC_d2b17
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_d2b17.dir/link.txt --verbose=1
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create CMakeFiles/cmTC_d2b17.dir/CheckFunctionExists.c.o -o cmTC_d2b17 -lpthreads
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_d2b17.dir/build.make:87: cmTC_d2b17] Error 1
make[1]: Leaving directory '/home/user/ros2_ws/build/my_interfaces/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_d2b17/fast] Error 2
CMakeLists.txt
file contents:
cmake_minimum_required(VERSION 3.5)
project(my_interfaces)
# 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(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(action_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
"srv/FindWall.srv"
"action/OdomRecord.action"
)
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()
package.xml
file contents:
<?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>my_interfaces</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="user@todo.todo">user</maintainer>
<license>TODO: License declaration</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<depend>rclcpp</depend>
<depend>std_msgs</depend>
<depend>geometry_msgs</depend>
<depend>action_msgs</depend>
<depend>rosidl_default_generators</depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Please let me know if you would also require CMakeOutput.log
file contents. The contents are large, so I removed it from this post.
I tried to Google this issue, but this seems to be more of a fix required on your side, I believe.
Please fix this issue and let me know!
Thanks
Girish