【问题标题】:'mutex' is not a member of 'std' in MinGW 5.3.0'mutex' 不是 MinGW 5.3.0 中'std' 的成员
【发布时间】:2017-10-07 10:20:19
【问题描述】:

我正在使用 MinGW 5.3.0 和 Crypto++ 5.6.5:

C:\MinGW>g++ -std=c++11 -s -D_WIN32_WINNT=0x0501 LOG.cpp -U__STRICT_ANSI__ Decclass.cpp \
-IC:\\MinGW\\ -IC:\\MinGW\\boost -LC:\\MinGW  -lssl -lcrypto -lcryptopp -lgdi32 -lPCRYPT \
 -lz -ltiny -lwsock32 -lws2_32 -lShlwapi

编译会出现以下错误。

c:\mingw\cryptopp565\include\cryptopp\misc.h:287:14: error: 'mutex' in namespace 'std'
does not name a typestatic std::mutex s_mutex;

c:\mingw\cryptopp565\include\cryptopp\misc.h:296:18: error: 'mutex' is not a member of
'std'std::lock_guard<std::mutex> lock(s_mutex);

它显示'mutex'不是'std'的成员

我需要另一个版本的 MinGW 吗? 或者我可以自己修复这个构建吗?

【问题讨论】:

  • 请不要将文字发布为图片,而是发布文字。
  • @Jonas 谢谢...
  • 您是否包含mutex
  • 是的,我包括了#include #include

标签: c++ c++11 mingw mutex crypto++


【解决方案1】:

我通过编辑路径“cryptopp565\include\cryptopp\misc.h”中的“misc.h”来解决此问题

misc.h 的顶部,我包含了 boost 库中的 mutex.hpp

#include "c:\mingw\include\boost\asio\detail\mutex.hpp"

我也将命名空间从 std 更改为 boost::asio::detail

static std::mutex s_mutex; 
static boost::asio::detail::mutex s_mutex;

【讨论】:

  • 我建议您访问config.h,并确保没有为您的配置定义定义CRYPTOPP_CXX11_SYNCHRONIZATION
【解决方案2】:

我想我们可能已经在 cryptopp Commit e4cef84883b2 上解决了这个 MinGW/C++11 问题。您应该从 Master 工作或执行 git pull,然后取消注释 CRYPTOPP_NO_CXX11config.h : 65 中的定义(左右):

// Define CRYPTOPP_NO_CXX11 to avoid C++11 related features shown at the
// end of this file. Some compilers and standard C++ headers advertise C++11
// but they are really just C++03 with some additional C++11 headers and
// non-conforming classes. You might also consider `-std=c++03` or
// `-std=gnu++03`, but they are required options when building the library
// and all programs. CRYPTOPP_NO_CXX11 is probably easier to manage but it may
// cause -Wterminate warnings under GCC. MSVC++ has a similar warning.
// Also see https://github.com/weidai11/cryptopp/issues/529
// #define CRYPTOPP_NO_CXX11 1

我认为问题在于,您遇到了与 Windows 相关的问题,以及它缺乏适当的 C++11 支持,但您间接地得到了这些问题。它们是间接的,因为 MinGW 和 GCC 是分层的。 MinGW 和 GCC 不可能提供 C++11,因为底层平台不能。

我认为此时最好的选择是定义CRYPTOPP_NO_CXX11。我不相信我们可以像在 Windows 上那样为您做到这一点,因为我们需要访问的定义隐藏在 MinGW 和 GCC 后面。我们还需要解决一些 MSVC++ 错误。

这是我们在 Windows 上的操作方式,但我们无法访问 MinGW 中的这些定义(来自 config.h : 950):

// Dynamic Initialization and Destruction with Concurrency ("Magic Statics")
// MS at VS2015 with Vista (19.00); GCC at 4.3; LLVM Clang at 2.9; Apple Clang at 4.0; Intel 11.1; SunCC 5.13.
// Microsoft's implementation only works for Vista and above, so its further
// limited. http://connect.microsoft.com/VisualStudio/feedback/details/1789709
#if (CRYPTOPP_MSC_VERSION >= 1900) && ((WINVER >= 0x0600) || (_WIN32_WINNT >= 0x0600)) || \
    (CRYPTOPP_LLVM_CLANG_VERSION >= 20900) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40000) || \
    (__INTEL_COMPILER >= 1110) || (CRYPTOPP_GCC_VERSION >= 40300) || (__SUNPRO_CC >= 0x5130)
# define CRYPTOPP_CXX11_DYNAMIC_INIT 1
#endif // Dynamic Initialization compilers

如果您定义了CRYPTOPP_NO_CXX11,那么将定义以下问题,您将避免这些问题:CRYPTOPP_CXX11_DYNAMIC_INITCRYPTOPP_CXX11_SYNCHRONIZATIONCRYPTOPP_CXX11_ATOMICS

【讨论】:

  • 他使用哪个 mingw 的问题。实际上有 c++17 AVAILABLE。事情是旧的 MinGW 线程开发人员不想为 x64 位平台实现。
  • 底层平台与语言实现可以提供什么无关。如果您使用带有“posix 线程”的 MinGW-w64 编译器,您将可以访问std::mutexstd::thread 等。这里真正的问题是 MinGW 5.3.0 已经完全过时了。
  • 我设法将 std::mutex 与 4.92 一起使用。我认为关键是缺少 -mthreads 标志。互斥头由几个预处理器条件保护。
【解决方案3】:

MINGW 仅支持带有 POSIX 线程的 std::thread 和 std::mutex,这绝对是非 POSIX 版本的差距。

现在,您无需为单个程序切换开发环境。

选项是从 POSIX 特定模板(由 _GLIBCXX_HAS_GTHREADS 选择的那些代码分支)或 MS-Sources 或 BOOST 库构建存根...

【讨论】:

    猜你喜欢
    • 2011-09-28
    • 2012-10-10
    • 2013-12-29
    相关资源
    最近更新 更多