ros-controls / gazebo_ros2_control

Wrappers, tools and additional API's for using ros2_control with Gazebo Classic
Apache License 2.0
210 stars 125 forks source link

Build Failure: Unable to Build gazebo_ros2_control on Windows #377

Open SENAI-GilmarCorreia opened 1 month ago

SENAI-GilmarCorreia commented 1 month ago

Description:

I am encountering an issue while trying to build the gazebo_ros2_control package on a Windows environment. The build fails with the following error log. I've anonymized any user-specific data in the output. Please advise on how to resolve this issue.

Error Log (Anonymized):

C:\Path\To\Anaconda\envs\gazebo\Library\include\absl/base/prefetch.h(183): warning C4100: 'addr': formal parameter not referenced
C:\Path\To\Anaconda\envs\gazebo\Library\include\google/protobuf/inlined_string_field.h(378): warning C4100: 'arena': formal parameter not referenced
C:\Path\To\Anaconda\envs\gazebo\Library\include\absl/container/internal/hashtablez_sampler.h(210): warning C4100: 'inline_element_size': formal parameter not referenced
C:\Path\To\Anaconda\envs\gazebo\Library\include\google/protobuf/descriptor.h(2239): warning C4100: 'message': formal parameter not referenced
C:\Path\To\Anaconda\envs\gazebo\Library\include\google/protobuf/descriptor.h(2238): warning C4100: 'location': formal parameter not referenced
C:\Path\To\Anaconda\envs\gazebo\Library\include\google/protobuf/descriptor.h(2238): warning C4100: 'descriptor': formal parameter not referenced
C:\Path\To\Anaconda\envs\gazebo\Library\include\google/protobuf/descriptor.h(2237): warning C4100: 'element_name': formal parameter not referenced
C:\Path\To\Anaconda\envs\gazebo\Library\include\google/protobuf/descriptor.h(2236): warning C4100: 'filename': formal parameter not referenced
C:\Path\To\Anaconda\envs\gazebo\Library\include\google/protobuf/descriptor.h(2246): warning C4100: 'message': formal parameter not referenced
C:\Path\To\Anaconda\envs\gazebo\Library\include\google/protobuf/descriptor.h(2245): warning C4100: 'location': formal parameter not referenced
C:\Path\To\Anaconda\envs\gazebo\Library\include\google/protobuf/descriptor.h(2245): warning C4100: 'descriptor': formal parameter not referenced
C:\Path\To\Anaconda\envs\gazebo\Library\include\google/protobuf/descriptor.h(2244): warning C4100: 'element_name': formal parameter not referenced
C:\Path\To\Anaconda\envs\gazebo\Library\include\google/protobuf/descriptor.h(2243): warning C4100: 'filename': formal parameter not referenced
C:\Path\To\Anaconda\envs\gazebo\Library\include\google/protobuf/map.h(689): warning C4244: 'initializing': conversion from 'uintptr_t' to 'google::protobuf::internal::map_index_t', possible loss of data
C:\Path\To\Anaconda\envs\gazebo\Library\include\gazebo-11\gazebo/common/Dem.hh(121): warning C4373: 'gazebo::common::Dem::FillHeightMap': virtual function overrides 'gazebo::common::HeightmapData::FillHeightMap', previous versions of the compiler did not override when parameters differed only in const/volatile qualifiers
C:\Path\To\Anaconda\envs\gazebo\Library\include\gazebo-11\gazebo/common/HeightmapData.hh(55): note: see the declaration of 'gazebo::common::HeightmapData::FillHeightMap'
C:\Path\To\Desktop\YourProject\install\include\hardware_interface/types/hardware_interface_return_values.hpp(25): error C2143: syntax error: missing '}' before 'constant'
C:\Path\To\Desktop\YourProject\install\include\hardware_interface/types/hardware_interface_return_values.hpp(25): error C2059: syntax error: 'constant'
C:\Path\To\Desktop\YourProject\install\include\hardware_interface/types/hardware_interface_return_values.hpp(26): error C2143: syntax error: missing ';' before '}'
C:\Path\To\Desktop\YourProject\install\include\hardware_interface/types/hardware_interface_return_values.hpp(28): error C2059: syntax error: '}'
C:\Path\To\Desktop\YourProject\install\include\hardware_interface/types/hardware_interface_return_values.hpp(28): error C2143: syntax error: missing ';' before '}'
C:\Path\To\Desktop\YourProject\install\include\hardware_interface/types/lifecycle_state_names.hpp(23): error C2143: syntax error: missing ';' before '{'
C:\Path\To\Desktop\YourProject\install\include\hardware_interface/types/lifecycle_state_names.hpp(23): error C2447: '{': missing function header (old-style formal list?)
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(53): error C2143: syntax error: missing '}' before 'constant'
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(53): error C2059: syntax error: 'constant'
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(54): error C2143: syntax error: missing ';' before '}'
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(54): error C2238: unexpected token(s) preceding ';'
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(62): error C2433: 'CallbackReturn': 'virtual' not allowed in data declarations
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(62): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(62): error C2146: syntax error: missing ';' before identifier 'on_configure'
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(62): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(70): error C2433: 'CallbackReturn': 'virtual' not allowed in data declarations
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(70): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(70): error C2146: syntax error: missing ';' before identifier 'on_cleanup'
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(70): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(78): error C2433: 'CallbackReturn': 'virtual' not allowed in data declarations
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(78): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(78): error C2146: syntax error: missing ';' before identifier 'on_shutdown'
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(78): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(86): error C2433: 'CallbackReturn': 'virtual' not allowed in data declarations
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(86): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(86): error C2146: syntax error: missing ';' before identifier 'on_activate'
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(86): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(94): error C2433: 'CallbackReturn': 'virtual' not allowed in data declarations
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(94): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(94): error C2146: syntax error: missing ';' before identifier 'on_deactivate'
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(94): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(102): error C2433: 'CallbackReturn': 'virtual' not allowed in data declarations
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(102): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(102): error C2146: syntax error: missing ';' before identifier 'on_error'
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(102): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(106): error C2588: '::~LifecycleNodeInterface': invalid global destructor
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(106): error C2575: 'LifecycleNodeInterface': only member functions and base classes can be virtual
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(106): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(106): error C2491: 'rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface': dllimport function definition not allowed
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(106): warning C4508: 'rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface': function should return a value; return type 'void' assumed
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(110): error C2059: syntax error: '}'
<path_to_ros>/include/rclcpp_lifecycle/rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp(110): error C2143: syntax error: missing ';' before '}'

Environment:

I have already installed all necessary dependencies via vcpkg and configured the environment variables. Please let me know if additional details are required.

Steps to Reproduce:

  1. Clone gazebo_ros2_control repository.
  2. Run colcon build in the workspace on Windows.

Expected Behavior: The build should complete successfully without errors.

Actual Behavior: The build fails with the above-mentioned errors.

christophfroehlich commented 1 month ago

The error messages come already from ros2_control and dependencies like rclcpp_lifecycle. We do not officially support ros2_control compilation on Windows (we don't have CI for that etc..). Were your able to build the ros2_control stack (without gazebo)?

SENAI-GilmarCorreia commented 1 month ago

Yes, I was able to build ros2_control, ros2_controllers, and gazebo_ros_pkgs. However, some packages may be broken on Windows, such as pid_controller. I'm just curious to get this working on Windows! :)

christophfroehlich commented 1 month ago

But there is a syntax error reported in hardware_interface, how can you compile that in ros2_control? Is gazebo classic running on Windows at all? Just to avoid running into a dead end with this package here.

SENAI-GilmarCorreia commented 1 month ago

@christophfroehlich I used the following command:

colcon build --symlink install --packages-select hardware_interface --cmake-args -DCMAKE_PREFIX_PATH="C:/boost" -DBOOST_ROOT="C:/boost" -DBoost_NO_SYSTEM_PATHS=ON -DBUILD_TESTING=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON -DPython3_EXECUTABLE="C:/Python38/python.exe"

And Gazebo is working like a charm (with a good fps). However, two plugins, gazebo_init and gazebo_ray_sensor from gazebo_ros_pkgs, are not working. I'm not using WSL.

imagem_2024-09-24_152808962

christophfroehlich commented 1 month ago

Why you should get syntax errors in the file included in gazebo_ros2_control, if it works if compiled separately? Sorry, I can't help you further here, never used ROS on Windows. fyi: You will need the gazebo_ros_init plugin to have the sim_time in the ROS world

SENAI-GilmarCorreia commented 1 month ago

I don't know either 🤣. No problem, thank you for your support. If I find any solution to solve this installation on Windows, I'll share it with you all.

SENAI-GilmarCorreia commented 1 month ago

Just an update... I was able to minimize some errors using this code in the CMakeLists file:

if(WIN32)
  add_compile_definitions(
    # For math constants
    _USE_MATH_DEFINES
    # Minimize Windows namespace collision
    NOMINMAX
    WIN32_LEAN_AND_MEAN
  )
endif()

I have tried to split the build and see which errors are related to each plugin. The log from gazebo_ros2_control shows the following:

1>Checking Build System
  Building Custom Rule C:/path/to/gazebo_ros2_control/CMakeLists.txt
  gazebo_ros2_control_plugin.cpp
C:/path/to/gazebo_ros/include/gazebo_ros/node.hpp(44,1): warning C4275: no DLL interface class 'rclcpp::Node' used as the base for DLL interface class 'gazebo_ros::Node' [C:/path/to/gazebo_ros2_control.vcxproj]
C:/opt/ros/humble/include/rclcpp/rclcpp/node.hpp(77): message : see declaration of 'rclcpp::Node' [C:/path/to/gazebo_ros2_control.vcxproj]
C:/path/to/gazebo_ros/include/gazebo_ros/node.hpp(43): message : see declaration of 'gazebo_ros::Node' [C:/path/to/gazebo_ros2_control.vcxproj]
C:/path/to/controller_manager_msgs/controller_manager_msgs/srv/detail/switch_controller__struct.hpp(143,28): error C2059: syntax error: 'constant' [C:/path/to/gazebo_ros2_control.vcxproj]
C:/path/to/controller_manager_msgs/controller_manager_msgs/srv/detail/switch_controller__struct.hpp(216): message : see reference to instantiation of 'controller_manager_msgs::srv::SwitchController_Request_<ContainerAllocator>' being compiled [C:/path/to/gazebo_ros2_control.vcxproj]
C:/path/to/controller_manager_msgs/controller_manager_msgs/srv/detail/switch_controller__struct.hpp(144,1): error C2238: unexpected token(s) preceding ';' [C:/path/to/gazebo_ros2_control.vcxproj]
C:/path/to/controller_manager_msgs/controller_manager_msgs/srv/detail/switch_controller__struct.hpp(231,66): error C2589: 'constant': invalid token on right side of '::' [C:/path/to/gazebo_ros2_control.vcxproj]
C:/path/to/controller_manager_msgs/controller_manager_msgs/srv/detail/switch_controller__struct.hpp(231): error C2062: unexpected type 'unknown-type' [C:/path/to/gazebo_ros2_control.vcxproj]
C:/path/to/controller_manager_msgs/controller_manager_msgs/srv/detail/switch_controller__builder.hpp(28,3): error C2059: syntax error: ':' [C:/path/to/gazebo_ros2_control.vcxproj]
C:/path/to/controller_manager_msgs/controller_manager_msgs/srv/detail/switch_controller__builder.hpp(44,3): error C2059: syntax error: ':' [C:/path/to/gazebo_ros2_control.vcxproj]
C:/path/to/controller_manager_msgs/controller_manager_msgs/srv/detail/switch_controller__builder.hpp(60,3): error C2059: syntax error: ':' [C:/path/to/gazebo_ros2_control.vcxproj]
C:/path/to/controller_manager_msgs/controller_manager_msgs/srv/detail/switch_controller__builder.hpp(76,3): error C2059: syntax error: ':' [C:/path/to/gazebo_ros2_control.vcxproj]
C:/path/to/controller_manager_msgs/controller_manager_msgs/srv/detail/switch_controller__builder.hpp(92,3): error C2059: syntax error: ':' [C:/path/to/gazebo_ros2_control.vcxproj]
C:/path/to/controller_manager_msgs/controller_manager_msgs/srv/detail/switch_controller__builder.hpp(108,3): error C2059: syntax error: ':' [C:/path/to/gazebo_ros2_control.vcxproj]
C:/path/to/controller_manager_msgs/controller_manager_msgs/srv/detail/switch_controller__builder.hpp(124,3): error C2059: syntax error: ':' [C:/path/to/gazebo_ros2_control.vcxproj]
C:/path/to/controller_manager_msgs/controller_manager_msgs/srv/detail/switch_controller__builder.hpp(140,3): error C2059: syntax error: ':' [C:/path/to/gazebo_ros2_control.vcxproj]
C:/vcpkg/installed/x64-windows/include/google/protobuf/map.h(689,19): warning C4244: 'initializing': conversion from 'uintptr_t' to 'google::protobuf::internal::map_index_t', possible loss of data [C:/path/to/gazebo_ros2_control.vcxproj]

And the gazebo_hardware_plugins shows these:

Building Custom Rule C:/path/to/gazebo_ros2_control/CMakeLists.txt
  gazebo_system.cpp
C:/path/to/angles/include/angles/angles.h(38,1): warning C4005: '_USE_MATH_DEFINES': macro redefinition [C:/path/to/gazebo_hardware_plugins.vcxproj]
C:/path/to/gazebo_system.cpp : message : see previous definition of '_USE_MATH_DEFINES' [C:/path/to/gazebo_hardware_plugins.vcxproj]
C:/path/to/anaconda/envs/gazebo/Library/include/google/protobuf/map.h(689,19): warning C4244: 'initializing': conversion from 'uintptr_t' to 'google::protobuf::internal::map_index_t', possible loss of data [C:/path/to/gazebo_hardware_plugins.vcxproj]
C:/path/to/hardware_interface/types/hardware_interface_return_values.hpp(25,3): error C2143: syntax error: missing '}' before 'constant' [C:/path/to/gazebo_hardware_plugins.vcxproj]
C:/path/to/hardware_interface/types/hardware_interface_return_values.hpp(25,3): error C2059: syntax error: 'constant'
...
christophfroehlich commented 1 month ago

controller_manager_msgs are genereated by rosidl, this code is not part of our repos. There must be something different in the cmake file of gazebo_ros2_control compared to ros2_control to make your build fail.