在MinGW 5.3.0中,“互斥锁”不是“std”的成员。

8

我正在使用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版本吗? 还是我可以修复这个构建本身?


5
请勿将文本作为图片发布,应直接发布文本。 - Jonas
2
你是否包含了 mutex - taskinoor
是的,我包括了 #include <thread> 和 #include <mutex>。 - Amit.Desai
Crypto++ 5.6.4及以上版本包括<mutex>,但它基于编译器保护了该包含。请参考stdcpp.h from 5.6.4。如果MinGW没有提供该包含,则可能需要调整该包含。由于MinGW已被放弃并且很少有人使用它,因此我们看不到太多的MinGW测试。 (我无法读取您图片中的文本内容,因此建议您发布实际的文本内容)。 - jww
谢谢大家 "taskinoor" "Passer By" "jww"。 - Amit.Desai
显示剩余3条评论
3个回答

3

我通过编辑位于"path/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 - jww

1
MINGW仅支持使用POSIX线程的std :: thread和std :: mutex,这绝对是非POSIX版本的差距。
现在,您不需要为单个程序切换开发环境。
选项是从POSIX特定模板(由_GLIBCXX_HAS_GTHREADS选择的那些代码分支)或MS-Sources或BOOST库构建存根...

-1

我认为我们可能已经在cryptopp 提交 e4cef84883b2中基本解决了这个MinGW/C++11问题。您应该从Master进行工作或执行git pull,然后在config.h:65(大约)中取消注释 CRYPTOPP_NO_CXX11 的定义:

// 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是在其之上构建的。由于底层平台无法提供C++11,因此MinGW和GCC不可能提供。

我认为您现在最好的选择是定义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是可用的。问题在于旧版MinGW线程开发人员不想为x64位平台实现这个功能。 - Swift - Friday Pie
1
底层平台与语言实现所提供的内容无关。如果您使用带有“posix线程”的MinGW-w64编译器,您将可以访问std::mutexstd::thread等。真正的问题在于,MinGW 5.3.0已经过时了。 - rubenvb
我设法在4.92中使用了std::mutex,我认为关键是缺少-mthreads标志。互斥头由几个预处理器条件保护。 - Swift - Friday Pie

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接