Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails on Windows: Cannot open include file: 'sched.h' #131

Open
RobertoRoos opened this issue Nov 8, 2023 · 6 comments
Open

Build fails on Windows: Cannot open include file: 'sched.h' #131

RobertoRoos opened this issue Nov 8, 2023 · 6 comments

Comments

@RobertoRoos
Copy link

RobertoRoos commented Nov 8, 2023

I am trying to build and run the ROS2Control demo, but during building I run into the following error: Cannot open include file: 'sched.h'

I am following the instructions here: https://control.ros.org/master/doc/getting_started/getting_started.html#building-from-source
Using ROS2 Humble, with Windows 10.

The full build output is:

stdout_stderr.log

-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
-- Found ament_cmake: 1.3.5 (C:/dev/ros2_humble/share/ament_cmake/cmake)
-- Found rclcpp: 16.0.5 (C:/dev/ros2_humble/share/rclcpp/cmake)
-- Found rosidl_generator_c: 3.1.5 (C:/dev/ros2_humble/share/rosidl_generator_c/cmake)
-- Found rosidl_adapter: 3.1.5 (C:/dev/ros2_humble/share/rosidl_adapter/cmake)
-- Found rosidl_generator_cpp: 3.1.5 (C:/dev/ros2_humble/share/rosidl_generator_cpp/cmake)
-- Using all available rosidl_typesupport_c: rosidl_typesupport_fastrtps_c;rosidl_typesupport_introspection_c
-- Using all available rosidl_typesupport_cpp: rosidl_typesupport_fastrtps_cpp;rosidl_typesupport_introspection_cpp
-- Found rmw_implementation_cmake: 6.1.1 (C:/dev/ros2_humble/share/rmw_implementation_cmake/cmake)
-- Found rmw_fastrtps_cpp: 6.2.3 (C:/dev/ros2_humble/share/rmw_fastrtps_cpp/cmake)
-- Using RMW implementation 'rmw_fastrtps_cpp' as default
-- Found rclcpp_action: 16.0.5 (C:/dev/ros2_humble/share/rclcpp_action/cmake)
-- Found ament_cmake_gmock: 1.3.5 (C:/dev/ros2_humble/share/ament_cmake_gmock/cmake)
-- Found test_msgs: 1.2.1 (C:/dev/ros2_humble/share/test_msgs/cmake)
-- Found gmock sources under 'C:/dev/ros2_humble/src/gmock_vendor': C++ tests using 'Google Mock' will be built
-- Found ament_cmake_gtest: 1.3.5 (C:/dev/ros2_humble/share/ament_cmake_gtest/cmake)
-- Found gtest sources under 'C:/dev/ros2_humble/src/gtest_vendor': C++ tests using 'Google Test' will be built
-- Configuring done (4.1s)
-- Generating done (1.6s)
-- Build files have been written to: C:/Users/Name/project/ros2_control_ws/build/realtime_tools
MSBuild version 17.7.2+d6990bcfa for .NET Framework

1>Checking Build System
gmock.vcxproj -> C:\Users\Users\Name\project\ros2_control_ws\build\realtime_tools\gmock\Release\gmock.lib
gmock_main.vcxproj -> C:\Users\Users\Name\project\ros2_control_ws\build\realtime_tools\gmock\Release\gmock_main.lib
Building Custom Rule C:/Users/Name/project/ros2_control_ws/src/realtime_tools/CMakeLists.txt
realtime_tools.vcxproj -> C:\Users\Users\Name\project\ros2_control_ws\build\realtime_tools\Release\realtime_tools.dll
Building Custom Rule C:/Users/Name/project/ros2_control_ws/src/realtime_tools/CMakeLists.txt
LINK : fatal error LNK1181: cannot open input file 'Release\realtime_tools.lib' [C:\Users\Users\Name\project\ros2_control_ws\build\realtime_tools\realtime_box_tests.vcxproj]
Building Custom Rule C:/Users/Name/project/ros2_control_ws/src/realtime_tools/CMakeLists.txt
LINK : fatal error LNK1181: cannot open input file 'Release\realtime_tools.lib' [C:\Users\Users\Name\project\ros2_control_ws\build\realtime_tools\realtime_buffer_tests.vcxproj]
Building Custom Rule C:/Users/Name/project/ros2_control_ws/src/realtime_tools/CMakeLists.txt
LINK : fatal error LNK1181: cannot open input file 'Release\realtime_tools.lib' [C:\Users\Users\Name\project\ros2_control_ws\build\realtime_tools\realtime_clock_tests.vcxproj]
Building Custom Rule C:/Users/Name/project/ros2_control_ws/src/realtime_tools/CMakeLists.txt
LINK : fatal error LNK1181: cannot open input file 'Release\realtime_tools.lib' [C:\Users\Users\Name\project\ros2_control_ws\build\realtime_tools\realtime_publisher_tests.vcxproj]
Building Custom Rule C:/Users/Name/project/ros2_control_ws/src/realtime_tools/CMakeLists.txt
LINK : fatal error LNK1181: cannot open input file 'Release\realtime_tools.lib' [C:\Users\Users\Name\project\ros2_control_ws\build\realtime_tools\realtime_publisher_tests_non_polling.vcxproj]
Building Custom Rule C:/Users/Name/project/ros2_control_ws/src/realtime_tools/CMakeLists.txt
LINK : fatal error LNK1181: cannot open input file 'Release\realtime_tools.lib' [C:\Users\Users\Name\project\ros2_control_ws\build\realtime_tools\realtime_server_goal_handle_tests.vcxproj]
Building Custom Rule C:/Users/Name/project/ros2_control_ws/src/realtime_tools/CMakeLists.txt
thread_priority.cpp
C:\Users\Users\Name\project\ros2_control_ws\src\realtime_tools\src\thread_priority.cpp(31,10): fatal error C1083: Cannot open include file: 'sched.h': No such file or directory [C:\Users\Users\Name\project\ros2_control_ws\build\realtime_tools\thread_priority.vcxproj]

I am not sure to what extend Windows is even supported for ROS2Control, I hope this issue won't do any harm. Thanks!

@bmagyar
Copy link
Member

bmagyar commented Nov 8, 2023

Windows support: we do have all the boilerplate for DLLs in place. Everything else should be handled by ament but we don't have a windows CI so no means really to keep things building. You are welcome to propose a fix, the Linux CIs should help guide you to a compatible solution.

@bmagyar
Copy link
Member

bmagyar commented Nov 8, 2023

Please no #IF Windows :D

@bmagyar
Copy link
Member

bmagyar commented Nov 8, 2023

I found a simple solution, using cygwin/mingw (aka anything coming from gcc and the POSIX world) will have compatible versions: https://stackoverflow.com/questions/27667552/porting-sched-h-to-windows

@AustinMooreT
Copy link

Sorry to comment on an old issue, but if someone is in my shoes I got things to at least build with msvc with a tiny bit of cheap hackery.
Sadly I don't have the luxury of a minimal gnu implementation. I know this isn't ideal, but it'll get you building and linking, and hopefully no runtime errors?

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4743d98..06e5e6a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,6 +3,9 @@ project(realtime_tools LANGUAGES CXX)

 if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
   add_compile_options(-Wall -Wextra)
+elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
+  # windows needs a .lib with all of the exported symbols to link to a shared library
+  set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
 endif()

 set(THIS_PACKAGE_INCLUDE_DEPENDS
diff --git a/src/thread_priority.cpp b/src/thread_priority.cpp
index 72749e3..04e6960 100644
--- a/src/thread_priority.cpp
+++ b/src/thread_priority.cpp
@@ -28,7 +28,10 @@

 #include "realtime_tools/thread_priority.hpp"

+#ifdef __linux__
 #include <sched.h>
+#elif _WIN32
+#endif

 #include <cstring>
 #include <fstream>
@@ -37,20 +40,29 @@ namespace realtime_tools
 {
 bool has_realtime_kernel()
 {
+#ifdef __linux__
   std::ifstream realtime_file("/sys/kernel/realtime", std::ios::in);
   bool has_realtime = false;
   if (realtime_file.is_open()) {
     realtime_file >> has_realtime;
   }
   return has_realtime;
+#elif _WIN32
+  return false;  // TODO: is it possible to configure windows for realtime?
+#endif
 }

 bool configure_sched_fifo(int priority)
 {
+#ifdef __linux__
   struct sched_param schedp;
   memset(&schedp, 0, sizeof(schedp));
   schedp.sched_priority = priority;
   return !sched_setscheduler(0, SCHED_FIFO, &schedp);
+#elif _WIN32
+  return false;  // TODO: maybe add the ability to set proccess priority to realtime?
+                 // see https://stackoverflow.com/questions/27732280/porting-set-fifo-to-windows
+#endif
 }

 }  // namespace realtime_tools

@SENAI-GilmarCorreia
Copy link
Contributor

Hello @RobertoRoos! I think we solve this problem with the #170 , #179 and #180 PRs. Can you please check if this work to you?

Thank you

@RobertoRoos
Copy link
Author

Great to hear fixes have been merged, but unfortunately I cannot test this anymore, I don't have this software stack anymore.

I'll leave it up to you close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants