C++编译错误,std 中的互斥锁不会在 MinGW (GCC 6.3.0) 中命名类型

C++ compile error, mutex in std does not name a type in MinGW (GCC 6.3.0)

本文关键字:GCC MinGW 类型 std 错误 编译 C++      更新时间:2023-10-16

我正在尝试在Windows 10 64位上使用MinGW(G ++ 6.3.0(编译Mongo C++11驱动程序。来自 GCC 6 发行说明;

默认模式已更改为 -std=gnu++14。

我的理解是默认情况下也支持 C++11。那么为什么我会收到这些关于互斥锁和线程的错误消息?

from F:/Projects/Mongo/attempt_4_mingw64/mongo-cxx-driver-r3.1.1/src/mongocxx/exception/private/mongoc_error.hh:19,
from F:ProjectsMongoattempt_4_mingw64mongo-cxx-driver-r3.1.1srcmongocxxbulk_write.cpp:20:
F:/Projects/Mongo/attempt_4_mingw64/mongo-cxx-driver-r3.1.1/src/mongocxx/test_util/mock.hh:183:10: error: 'mutex' in namespace 'std' does not name a type
         std::mutex _active_instances_lock;
              ^~~~~
F:/Projects/Mongo/attempt_4_mingw64/mongo-cxx-driver-r3.1.1/src/mongocxx/test_util/mock.hh:184:24: error: 'thread' is not a member of 'std'
         std::unordered_map<std::thread::id, instance*> _active_instances;
                            ^~~
F:/Projects/Mongo/attempt_4_mingw64/mongo-cxx-driver-r3.1.1/src/mongocxx/test_util/mock.hh:184:24: error: 'thread' is not a member of 'std'
F:/Projects/Mongo/attempt_4_mingw64/mongo-cxx-driver-r3.1.1/src/mongocxx/test_util/mock.hh:184:50: error: wrong number of template arguments (1, should be at least 2) 
         std::unordered_map<std::thread::id, instance*> _active_instances;
                                                      ^

mongocxx目前只支持Windows上的MSVC,因此使用MinGW构建可能无法实现。话虽如此,如果你还没有,我建议在你的CMAKE_CXX_FLAGS中传递-std=c++11,看看这是否有效。