我正在使用“JetBrains CLion 2017.1”编写基于C ++ 11的多线程程序。代码在这里:
#include <stdlib.h>
#include <iostream>
#include <thread>
void thread_task() {
std::cout << "hello thread" << std::endl;
}
int main(int argc, const char *argv[])
{
std::thread t(thread_task);
t.join();
return EXIT_SUCCESS;
}
“CMakeLists.txt”是默认值:
cmake_minimum_required(VERSION 3.7)
project(AgileDev)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(AgileDev ${SOURCE_FILES})
我想知道我哪里错了。 (T ^ T)
答案 0 :(得分:1)
我有完全相同的错误。显然,如果你使用mingw它不支持标准线程。你应该下载:https://github.com/meganz/mingw-std-threads
并将mingw.mutex.h
和mingw.thread.h
添加到项目目录中。将此内容包含在cpp源文件的顶部。
#include "mingw.thread.h"
它应该工作