Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLion cannot resolve thread

Tags:

c++11

clion

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)

like image 417
Polylanger Avatar asked Jan 21 '26 05:01

Polylanger


1 Answers

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

like image 200
juanagbp Avatar answered Jan 23 '26 20:01

juanagbp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!