CLion无法解析线程

时间:2017-04-03 16:02:57

标签: c++11 clion

我正在使用“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})

但是CLion无法解决“线程”: 错误图片 enter image description here

我想知道我哪里错了。 (T ^ T)

1 个答案:

答案 0 :(得分:1)

我有完全相同的错误。显然,如果你使用mingw它不支持标准线程。你应该下载:https://github.com/meganz/mingw-std-threads

并将mingw.mutex.hmingw.thread.h添加到项目目录中。将此内容包含在cpp源文件的顶部。

#include "mingw.thread.h"

它应该工作