【问题标题】:C++ compile error, mutex in std does not name a type in MinGW (GCC 6.3.0)C++ 编译错误,std 中的互斥锁没有在 MinGW (GCC 6.3.0) 中命名类型
【发布时间】:2017-11-17 23:08:26
【问题描述】:

我正在尝试在 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:\Projects\Mongo\attempt_4_mingw64\mongo-cxx-driver-r3.1.1\src\mongocxx\bulk_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;
                                                      ^

【问题讨论】:

  • 您是否正在运行一个构建系统,可以让您查看执行的命令?哪些标志被传递给编译器?你也能证明这一点吗?使用的编译器真的是你所期望的吗?
  • @Someprogrammerdude,我使用的是 CMake 3.8,它提供了这种输出 -- Check for working CXX compiler: C:/MinGW64/bin/g++.exe -- works。所以肯定它使用 G++,我唯一的版本是 6.3.0。
  • 如果您运行make VERBOSE=1,您将看到传递给编译器的标志。类似-std=c++03(或类似)的东西是否传递给编译器?

标签: c++ mongodb c++11 gcc mingw


【解决方案1】:

mongocxx 当前为only supports MSVC on Windows,因此可能无法使用 MinGW 进行构建。话虽如此,如果您还没有这样做,我建议您在 CMAKE_CXX_FLAGS 中传递 -std=c++11 以查看是否可行。

【讨论】:

    猜你喜欢
    • 2012-12-20
    • 2016-07-05
    • 1970-01-01
    • 2023-01-05
    • 2021-07-19
    • 1970-01-01
    • 2015-10-06
    • 1970-01-01
    相关资源
    最近更新 更多