【发布时间】:2019-11-17 02:27:58
【问题描述】:
我尝试在 c++ 中编译一个简单的 c++ 代码,但是当我尝试在 windows 中使用 g++ 编译它时不断返回错误。
我用
g++ -std=c++0x -pthread main.cpp
错误信息是:
std::thread' is defined in header '<thread>'; did you forget to '#include <thread>'?
这没有意义,因为代码只是
#include<thread>
void f(int i) {}
int main() {
std::thread t(f, 1);
t.join();
return 0;
}
我相信这段代码在linux下可以工作,我想知道为什么它不能在windows下工作。
【问题讨论】:
-
<thread>是 C++11 或更高版本的标头。您是在告诉 g++ 使用旧版本的语言。 -
您还应该检查您使用的 g++ 的任何 Windows 端口是否支持 C++11 线程。
-pthread选项在 Windows 上也有点奇怪......或者你的 G++ 是否使用 Windows 端口的 pthreads 而不是本机 Win32 线程?
标签: c++ multithreading c++11 g++