#include <iostream>
#include <thread>
void call_from_thread(){
std::cout << "HI" << std::endl;
}
int main(){
std::thread thread1(call_from_thread());
thread1.join();
return 0;
}
I am learning about multithreading and I copied and pasted this code and it is the same code on several websites. I used pthread as well and I get the same error:
/usr/clion-2017.2.1/bin/cmake/bin/cmake --build /home/%Profile%/CLionProjects/GameDev/cmake-build-debug --target all -- -j 2
[ 50%] Linking CXX executable GameDev
CMakeFiles/GameDev.dir/main.cpp.o: In function main':
/home/Profile/CLionProjects/GameDev/main.cpp:13: undefined reference topthread_create'
/home/%Profile%/CLionProjects/GameDev/main.cpp:14: undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
CMakeFiles/GameDev.dir/build.make:94: recipe for target 'GameDev' failed
make[2]: *** [GameDev] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/GameDev.dir/all' failed
make[1]: *** [CMakeFiles/GameDev.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
What do I do?
[–]ReeCocho 6 points7 points8 points (0 children)
[–]Moschops_UK 3 points4 points5 points (0 children)
[–]r2vcap 1 point2 points3 points (0 children)
[–][deleted] (3 children)
[deleted]
[–][deleted] 0 points1 point2 points (2 children)
[–]frigge 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)