4

I'm writing a Multithreading program based on C++ 11 using "JetBrains CLion 2017.1". The code is here:

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

And the "CMakeLists.txt" is default:

cmake_minimum_required(VERSION 3.7)
project(AgileDev)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp)
add_executable(AgileDev ${SOURCE_FILES})

But CLion cannot resolve "thread": Error picture enter image description here

I wondered where I was wrong. (T^T)

isuruAb
  • 2,202
  • 5
  • 26
  • 39
Polylanger
  • 41
  • 1
  • 3
  • 1
    This link is for eclipse, but you cold be facing a similar issue: http://stackoverflow.com/questions/32184177/c-error-type-stdthread-could-not-be-resolved-eclipse-mars-4-5-ubuntu-12 – BusyProgrammer Apr 04 '17 at 00:16

1 Answers1

1

I had the exact same error. Apparently if you are using mingw it doesn't support standard threads. You should download this: https://github.com/meganz/mingw-std-threads

and add mingw.mutex.h and mingw.thread.h to your project directory.Include this at the top of your cpp source file.

#include "mingw.thread.h"

It should work then

juanagbp
  • 11
  • 1