繁体   English   中英

我应该在 windows 上拥有什么才能使用 std::mutex?

[英]What should i have on windows to use std::mutex?

尝试使用 C++ std::mutex时,我在 Windows 10 64 位上遇到错误。 该代码基本上是为 Linux 编写的,但我正在尝试将其移植到 Windows。 (您可以在我在下面添加的错误消息中看到编译器行。)

这是我的代码:

#ifndef UNTITLED_LIBRARY_H
#define UNTITLED_LIBRARY_H

#include <sys/types.h>
#include <Winsock2.h>
#include <mutex>
#include <thread>

class TCPServer
{
    static std::mutex mt;
};

#endif //UNTITLED_LIBRARY_H
Here is the error message:

g++ -Wall -std=c++14  -I./ library.h  -o libSimpleNetwork.so -fPIC -shared
library.h:11:17: error: 'mutex' in namespace 'std' does not name a type
   11 |     static std::mutex mt;
      |                 ^~~~~
library.h:8:1: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
    7 | #include <thread>
  +++ |+#include <mutex>
    8 |


所以这个问题的答案是安装mingw64(不是mingw32:): https://sourceforge.net/projects/mingw-w64/

这包括 gcc 需要用于 libstd 的 posix x86_64-posix-seh

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM