machines-in-motion / shared_memory

realtime interprocess communication
BSD 3-Clause "New" or "Revised" License
5 stars 1 forks source link

Library is potentially incompatible with Boost 1.8 #34

Open TaqiHamoda opened 1 year ago

TaqiHamoda commented 1 year ago

I am trying to build the library but I get the following compilation errors:

/home/.../shared_memory/src/locked_condition_variable.cpp: In member function 'bool shared_memory::LockedConditionVariable::timed_wait(long int)':
/home/.../shared_memory/src/locked_condition_variable.cpp:64:16: error: 'boost::posix_time' has not been declared
   64 |         boost::posix_time::ptime current_time =
      |                ^~~~~~~~~~
/home/.../shared_memory/src/locked_condition_variable.cpp:66:16: error: 'boost::posix_time' has not been declared
   66 |         boost::posix_time::time_duration waiting_time =
      |                ^~~~~~~~~~
/home/.../shared_memory/src/locked_condition_variable.cpp:70:48: error: 'current_time' was not declared in this scope
   70 |                                                current_time + waiting_time);
      |                                                ^~~~~~~~~~~~
/home/.../shared_memory/src/locked_condition_variable.cpp:70:63: error: 'waiting_time' was not declared in this scope
   70 |                                                current_time + waiting_time);
      |                                                               ^~~~~~~~~~~~
/home/.../shared_memory/src/locked_condition_variable.cpp:60:47: warning: unused parameter 'wait_nano_seconds' [-Wunused-parameter]
   60 | bool LockedConditionVariable::timed_wait(long wait_nano_seconds)
      |                                          ~~~~~^~~~~~~~~~~~~~~~~

These issues were resolved when I added the #include <boost/date_time/posix_time/posix_time.hpp> header to shared_memory.hpp. There are other compilation issues that are also resolved by adding the appropriate headers.

TaqiHamoda commented 1 year ago

It has been a while and there is no reply. I tried doing a pull request but I got an unauthorized error. Since there is no support, I will post a diff of my changes in case anyone faces the same issue I did.

diff --git a/include/shared_memory/shared_memory.hpp b/include/shared_memory/shared_memory.hpp
index 0738b93..0c080ff 100644
--- a/include/shared_memory/shared_memory.hpp
+++ b/include/shared_memory/shared_memory.hpp
@@ -26,6 +26,7 @@

 #include <Eigen/Dense>

+#include <boost/date_time/posix_time/posix_time.hpp>
 #include <boost/interprocess/allocators/allocator.hpp>
 #include <boost/interprocess/containers/deque.hpp>
 #include <boost/interprocess/containers/string.hpp>
diff --git a/src/condition_variable.cpp b/src/condition_variable.cpp
index 54bdbb8..b84fb42 100644
--- a/src/condition_variable.cpp
+++ b/src/condition_variable.cpp
@@ -48,7 +48,7 @@ void ConditionVariable::wait(Lock &lock)
 bool ConditionVariable::timed_wait(Lock &lock, long wait_nano_seconds)
 {
     boost::posix_time::ptime current_time =
-        boost::interprocess::microsec_clock::universal_time();
+        boost::posix_time::microsec_clock::universal_time();
     boost::posix_time::time_duration waiting_time =
         boost::posix_time::microseconds(
             static_cast<long>(static_cast<double>(wait_nano_seconds) * 0.001));
diff --git a/src/locked_condition_variable.cpp b/src/locked_condition_variable.cpp
index d3fafb1..17221f3 100644
--- a/src/locked_condition_variable.cpp
+++ b/src/locked_condition_variable.cpp
@@ -62,7 +62,7 @@ bool LockedConditionVariable::timed_wait(long wait_nano_seconds)
     if (lock_)
     {
         boost::posix_time::ptime current_time =
-            boost::interprocess::microsec_clock::universal_time();
+            boost::posix_time::microsec_clock::universal_time();
         boost::posix_time::time_duration waiting_time =
             boost::posix_time::microseconds(static_cast<long>(
                 static_cast<double>(wait_nano_seconds) * 0.001));