2017-04-03 90 views
1

我正在使用「JetBrains CLion 2017.1」編寫基於C++ 11的多線程程序。該代碼是在這裏:CLion無法解析線程

#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}) 

但克利翁無法解決 「線程」: 錯誤畫面 enter image description here

我不知道我哪裏錯了。 (T^T)

+1

此鏈接是Eclipse,但你冷麪臨一個類似的問題:http://stackoverflow.com/questions/32184177/c-error-type-stdthread-could -not待解決-蝕-MARS-4-5-的ubuntu-12 –

回答

1

我有完全相同的錯誤。顯然,如果你使用的是mingw,它不支持標準線程。您應該下載此文件:https://github.com/meganz/mingw-std-threads

並將mingw.mutex.hmingw.thread.h添加到您的項目目錄中。在cpp源文件的頂部包含此項。

#include "mingw.thread.h" 

它應該工作,然後