zeromq / libzmq

ZeroMQ core engine in C++, implements ZMTP/3.1
https://www.zeromq.org
Mozilla Public License 2.0
9.64k stars 2.35k forks source link

error: 'condition_variable_any' in namespace 'std' does not name a type with WIN32 Threading #3859

Open CommanderBubble opened 4 years ago

CommanderBubble commented 4 years ago

Issue description

Building on Windows with MinGW_w64 fails when using Win32 threading model, using CMake and Ninja

Environment

Minimal test code / Steps to reproduce the issue

make MinGW w64 gcc with WIN32 threading model detected compiler build using CMake and Ninja.

What's the actual result? (include assertion message & call stack if applicable)

[0/1] Re-running CMake...
-- Detected ZMQ Version - 4.3.2
-- Using tweetnacl for CURVE security
-- Using polling method in I/O threads: select
-- Using polling method in zmq_poll(er)_* API: select
-- Using 64 bytes alignment for lock-free data structures
-- Detected _WIN32_WINNT from CMAKE_SYSTEM_VERSION: 0x0A00
-- Using condition_variable_t implementation: stl11
-- Checking whether noexcept is supported
-- Checking whether SOCK_CLOEXEC is supported
-- Checking whether O_CLOEXEC is supported
-- Checking whether SO_BINDTODEVICE is supported
-- Checking whether SO_KEEPALIVE is supported
-- Checking whether TCP_KEEPCNT is supported
-- Checking whether TCP_KEEPIDLE is supported
-- Checking whether TCP_KEEPINTVL is supported
-- Checking whether TCP_KEEPALIVE is supported
-- Checking whether TIPC is supported
-- Checking pthread_setname signature
-- Checking pthread_setaffinity signature
-- Checking whether getrandom is supported
-- Could NOT find AsciiDoc (missing: ASCIIDOC_EXECUTABLE)
-- capsh not found, skipping tests that require CAP_NET_ADMIN
CMake Warning (dev) at tests/CMakeLists.txt:294 (message):
  Test 'test_socks' is not known to CTest.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring done
-- Generating done
-- Build files have been written to: C:/Code/ZMQ/Latest/cmake
[25/378] Building CXX object CMakeFiles/libzmq.dir/src/mailbox_safe.cpp.obj
FAILED: CMakeFiles/libzmq.dir/src/mailbox_safe.cpp.obj
C:\Code\mingw-w64\mingw64\bin\c++.exe  -DDLL_EXPORT -DFD_SETSIZE=16384 -DZMQ_CUSTOM_PLATFORM_HPP -D_CRT_SECURE_NO_WARNINGS -D_REENTRANT -D_THREAD_SAFE -D_WIN32_WINNT=0x0A00 -D_WINSOCK_DEPRECATED_NO_WARNINGS -Dlibzmq_EXPORTS -I../include -I. -std=gnu++11 -Wno-tautological-constant-compare -O3 -DNDEBUG -MD -MT CMakeFiles/libzmq.dir/src/mailbox_safe.cpp.obj -MF CMakeFiles\libzmq.dir\src\mailbox_safe.cpp.obj.d -o CMakeFiles/libzmq.dir/src/mailbox_safe.cpp.obj -c ../src/mailbox_safe.cpp
In file included from ../src/mailbox_safe.hpp:43,
                 from ../src/mailbox_safe.cpp:31:
../src/condition_variable.hpp:140:10: error: 'condition_variable_any' in namespace 'std' does not name a type
     std::condition_variable_any _cv;
          ^~~~~~~~~~~~~~~~~~~~~~
../src/condition_variable.hpp:140:5: note: 'std::condition_variable_any' is defined in header '<condition_variable>'; did you forget to '#include <condition_variable>'?
../src/condition_variable.hpp:107:1:
+#include <condition_variable>

../src/condition_variable.hpp:140:5:
     std::condition_variable_any _cv;
     ^~~
../src/condition_variable.hpp: In member function 'int zmq::condition_variable_t::wait(zmq::mutex_t*, int)':
../src/condition_variable.hpp:122:13: error: '_cv' was not declared in this scope
             _cv.wait (
             ^~~
../src/condition_variable.hpp:122:13: note: suggested alternative: 'recv'
             _cv.wait (
             ^~~
             recv
../src/condition_variable.hpp:124:20: error: '_cv' was not declared in this scope
         } else if (_cv.wait_for (*mutex_, std::chrono::milliseconds (timeout_))
                    ^~~
../src/condition_variable.hpp:124:20: note: suggested alternative: 'recv'
         } else if (_cv.wait_for (*mutex_, std::chrono::milliseconds (timeout_))
                    ^~~
                    recv
../src/condition_variable.hpp:125:28: error: 'std::cv_status' has not been declared
                    == std::cv_status::timeout) {
                            ^~~~~~~~~
../src/condition_variable.hpp: In member function 'void zmq::condition_variable_t::broadcast()':
../src/condition_variable.hpp:136:9: error: '_cv' was not declared in this scope
         _cv.notify_all ();
         ^~~
../src/condition_variable.hpp:136:9: note: suggested alternative: 'recv'
         _cv.notify_all ();
         ^~~
         recv
At global scope:
cc1plus.exe: warning: unrecognized command line option '-Wno-tautological-constant-compare'
[34/378] Building CXX object CMakeFiles/libzmq.dir/src/norm_engine.cpp.obj
ninja: build stopped: subcommand failed.

What's the expected result?

The build should be able to succeed or

CommanderBubble commented 4 years ago

just tested same build for 4.3.1, the issue does not exist there

CommanderBubble commented 4 years ago

Looking at condition_variable.hpp, the checking around windows changed between releases. The check for which version is now done by cmake, setting (in my particular case) the variable ZMQ_USE_CV_IMPL_STL11 to 1, and for some reason this is not able to build.

gojmpz commented 3 years ago

I've encountered the same issue in libzmq version 4.3.3:

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had activity for 365 days. It will be closed if no further activity occurs within 56 days. Thank you for your contributions.

agowa commented 2 years ago

same issue with 4.3.4

Taywee commented 2 years ago

I ended up on this issue due to having a similar issue on AIX. For other people in the same boat, make sure you have -pthread in your CFLAGS, CXXFLAGS, and LDFLAGS. -lpthread isn't sufficient on AIX, and C++ types depending on threading won't be present.

sneurlax commented 1 year ago

I am having the same issue

sneurlax commented 1 year ago

I was able to move past this issue by reverting to 4.3.1 as @CommanderBubble said! Version 4.3.4 also has this issue.

paddor commented 8 months ago

Any updates here? I'm running into the same issue while building the Windows Ruby gems for czmq-ffi-gen.

I'm using v4.3.5

...
[ 25%] Building CXX object CMakeFiles/libzmq.dir/src/msg.cpp.obj
[ 25%] Building CXX object CMakeFiles/libzmq-static.dir/src/epoll.cpp.obj
In file included from /czmq-ffi-gen/vendor/libzmq/src/mailbox_safe.hpp:16,
                 from /czmq-ffi-gen/vendor/libzmq/src/mailbox_safe.cpp:4:
/czmq-ffi-gen/vendor/libzmq/src/condition_variable.hpp:102:10: error: 'condition_variable_any' in namespace 'std' does not name a type
  102 |     std::condition_variable_any _cv;
      |          ^~~~~~~~~~~~~~~~~~~~~~
/czmq-ffi-gen/vendor/libzmq/src/condition_variable.hpp:71:1: note: 'std::condition_variable_any' is defined in header '<condition_variable>'; did you forget to '#include <condition_variable>'?
   70 | #include <condition_variable>
  +++ |+#include <condition_variable>
   71 |

The suggestion about including <condition_variable> is already in src/condition_variable.hpp.

Docker image: Ubuntu 22.04 (building for mingw)

vadtec commented 2 months ago

Version 4.3.5 Cross-compile from Debian to MinGW using the MinGW suit.

If anyone has encountered this, I solved it by using ./configure --with-cv-impl=pthread .....