gpt4 book ai didi

c++ - minGW(使用 g++ 4.7.1)不编译简单的 C++11 代码(在 WinVista 下)

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:27:56 25 4
gpt4 key购买 nike

我做了功课并在这里和网上搜索了答案。下面的简单代码未编译:

#include <thread>
#include <iostream>

void hello()
{
std::cout << "Hello from thread " << std::endl;
}

int main()
{
std::thread t1(hello);
t1.join();
return 0;
}

这是非常简单的代码,但我收到以下错误:

Thread_Cpp11_002.cpp: In function 'int main()'
Thread_Cpp11_002.cpp:14:5: error: 'thread' is not a member of 'std'
Thread_Cpp11_002.cpp:14:17: error: expected ';' before 't1'
Thread_Cpp11_002.cpp:15:5: error: 't1' was not declared in this scope

我已经尝试了很多东西,但都没有用:

  1. 使用 thread 而不是 std::thread 声明 t1
  2. 使用 g++ 4.8.0 编译
  3. 单独和一起使用以下标志:-pthread-std=gnu++11-std=c++0x, -std=c++11...

所以,我认为这个问题值得在这里发布。

这些编译是通过命令行完成的。在我让它工作之后,我将尝试使用 Code::Blocks 12.11,它适用于 C++98。

请记住,我使用的是 Windows Vista。

最佳答案

这是一些 MinGW 构建的众所周知的问题(只需在您的 favorite engine 中搜索 mingw thread)。如果您需要线程支持,则必须使用另一个库(例如 boost 或 native Windows API)或不同的构建。

关于c++ - minGW(使用 g++ 4.7.1)不编译简单的 C++11 代码(在 WinVista 下),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16227620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com