Errors during messages compilation in ROS2
I get these errors and warning:
/home/le/master/build/rtabmap_ros/rosidl_generator_py/rtabmap_ros/msg/_info_s.c:686:23: warning: implicit declaration of function ‘PyLong_AsSize_t’; did you mean ‘PyLong_AsSsize_t’? [-Wimplicit-function-declaration]
size_t itemsize = PyLong_AsSize_t(itemsize_attr);
^~~~~~~~~~~~~~~
PyLong_AsSsize_t
/home/le/master/build/rtabmap_ros/rosidl_generator_py/rtabmap_ros/_rtabmap_ros_s.ep.rosidl_typesupport_c.c:9:15: error: variable ‘rtabmap_ros__module’ has initializer but incomplete type
static struct PyModuleDef rtabmap_ros__module = {
^~~~~~~~~~~
Even though my messages are quite normal:
#std_msgs/Header header
# Set either node_id or node_label
int32 node_id
string node_label
# optional: if not set, the base frame of the robot is used
string frame_id
What could be the reason?
Part of my CMakeLists:
find_package(ament_cmake REQUIRED)
find_package(rclcpp)
find_package(cv_bridge)
find_package(sensor_msgs)
find_package(builtin_interfaces REQUIRED)
find_package(rosidl_default_generators REQUIRED)
set(msg_files
"msg/Info.msg")
rosidl_generate_interfaces(${PROJECT_NAME}
${msg_files}
DEPENDENCIES builtin_interfaces std_msgs geometry_msgs
ADD_LINTER_TESTS
)
EDIT:
Here is my full msg, even though from my side, that did not make any difference:
#std_msgs/Header header
int32 ref_id
int32 loop_closure_id
int32 proximity_detection_id
geometry_msgs/Transform loop_closure_transform
####
# For statistics...
####
# std::map<int, float> posterior;
int32[] posterior_keys
float32[] posterior_values
# std::map<int, float> likelihood;
int32[] likelihood_keys
float32[] likelihood_values
# std::map<int, float> raw_likelihood;
int32[] raw_likelihood_keys
float32[] raw_likelihood_values
# std::map<int, int> weights;
int32[] weights_keys
int32[] weights_values
# std::map<int, std::string> labels;
int32[] labels_keys
string[] labels_values
# std::map<std::string, float> stats
string[] stats_keys
float32[] stats_values
# std::vector<int> local_path
int32[] local_path
int32 current_goal_id
Asked by EdwardNur on 2019-08-10 13:15:50 UTC
Answers
The first error you are getting is because you have a misspelling. You declared the function as PyLong_AsSsize_t()
instead of PyLong_AsSize_t()
. You essentially added as extra s
to when you declared the function.
The second says that your variable rtabmap_ros__module
has an incomplete type, so there is more to the type name than just PyModuleDef
maybe.
I was able to get your code to run with the following
msg/Info.msg
:
int32 node_id
string node_label
string frame_id
CMakeLists.txt
:
cmake_minimum_required(VERSION 3.5)
project(test_msgs)
# 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(std_msgs REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(rosidl_default_generators REQUIRED)
set(msg_files
"msg/Info.msg"
)
rosidl_generate_interfaces(${PROJECT_NAME}
${msg_files}
DEPENDENCIES builtin_interfaces std_msgs
ADD_LINTER_TESTS
)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif()
ament_package()
and package.xml
:
<?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>test_msgs</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="some@email.com">zmk5</maintainer>
<license>TODO: License declaration</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<build_depend>std_msgs</build_depend>
<build_depend>builtin_interfaces</build_depend>
<build_depend>rosidl_default_generators</build_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>builtin_interfaces</exec_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Asked by zmk5 on 2019-08-10 14:34:09 UTC
Comments
@zmk5 yes but isn't something that ROS2 generated those python files? Because if you look at the files location, that was generated bu rosidl generator, not by me.
Asked by EdwardNur on 2019-08-10 15:38:47 UTC
I guess I'm not sure what you were doing to begin with. Are you compiling your own message? What does your CMakeLists.txt
file look like? is the message you wrote the whole file .msg
file you want to generate?
Asked by zmk5 on 2019-08-10 16:32:24 UTC
@zmk5 I have edited with CMakeLists.
Asked by EdwardNur on 2019-08-10 16:38:45 UTC
Are these in your package.xml
file?
<build_depend>builtin_interfaces</build_depend>
<build_depend>rosidl_default_generators</build_depend>
<exec_depend>builtin_interfaces</exec_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
I've tried compiling your message, but I can't seem to get the same error you are getting.
Asked by zmk5 on 2019-08-10 16:49:21 UTC
Also if you are using std_msgs
and geometry_msgs
as dependencies you should add them to find_package
and in your package.xml
.
Asked by zmk5 on 2019-08-10 17:46:39 UTC
@zmk5 Hmm, that is stange. The thing is that I did not write those functions where I am getting errors, I am pretty sure that rosidle_generator has some script which creates those functions based on the messages, as if you look at the location of the file, it is stored inside the folder of rosidl generator, not my folders. Yes, I have the same package.xml. I have also edited with my full message but the reason I did not paste it is to preserve the simplicity as even if I remove them, I get the same errors. May be I have some broken binaries of ROS2 dashing? I installed on Ubuntu via binaries 1 month ago
Asked by EdwardNur on 2019-08-11 04:52:57 UTC
Maybe update your packages using sudo apt update && sudo apt upgrade
? Could be a fix in the newer versions. I had an issue recently that was fixed by just updating my packages.
Asked by zmk5 on 2019-08-11 11:24:04 UTC
The generated code uses PyLong_AsSize_t
which is a valid function in the Python C API: https://docs.python.org/3/c-api/long.html#c.PyLong_AsSize_t
Maybe you are using an older not supported Python version to compile the code?
Do you have python3-dev
installed - if yes, which version (dpkg -l | grep python3-dev
)?
What does the following command output: cat build/rtabmap_ros/CMakeCache.txt | grep PYTHON_
Asked by Dirk Thomas on 2019-08-12 11:59:47 UTC
Comments
python3-dev
version: 3.6.7-1~18.04
The command output:
PYTHON_EXECUTABLE:FILEPATH=/usr/bin/python3
PYTHON_INCLUDE_DIR:PATH=/usr/include/python3.6m
PYTHON_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libpython3.6m.so
PYTHON_LIBRARY_DEBUG:FILEPATH=PYTHON_LIBRARY_DEBUG-NOTFOUND
PYTHON_VERSION:STRING=
//ADVANCED property for variable: PYTHON_EXECUTABLE
PYTHON_EXECUTABLE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: PYTHON_INCLUDE_DIR
PYTHON_INCLUDE_DIR-ADVANCED:INTERNAL=1
PYTHON_INSTALL_DIR:INTERNAL=lib/python3.6/site-packages
//ADVANCED property for variable: PYTHON_LIBRARY
PYTHON_LIBRARY-ADVANCED:INTERNAL=1
//ADVANCED property for variable: PYTHON_LIBRARY_DEBUG
PYTHON_LIBRARY_DEBUG-ADVANCED:INTERNAL=1
PYTHON_SOABI:INTERNAL=cpython-36m-x86_64-linux-gnu
Asked by EdwardNur on 2019-08-12 15:30:58 UTC
The version numbers and info looks all correct. In which locations is the Python header (locate Python.h
)? Also try building with VERBOSE=1
set before and post the compiler invocation which will show all used include directories.
Asked by Dirk Thomas on 2019-08-12 15:43:56 UTC
Comments