I decided to make some threads research in C++. Everything was great, Visual Studio compiled it easily. But when I decided to compile all of that stuff by using Ubuntu terminal for Windows - I ran into mistake below. I tried to compile like:
- g++ -o thread ThreadTest.cpp
- g++ --std=c++17 -o thread ThreadTest.cpp
Have already tried to use #include <pthread.h>
, but it cannot be found in Visual Studio.
I'm also using lambda, there are all includes from my code:
#include <chrono>
#include <functional>
#include <iostream>
#include <thread>
#include <vector>
And this is what I take when I'm trying to compile it by Ubuntu:
In function `std::thread::thread<main::{lambda()#1}>(main::{lambda()#1}&&)':
ThreadTest.cpp:(.text+0x8b7): undefined reference to `pthread_create'
/tmp/cc0NzGGt.o: In function `std::thread::thread<void (&)(std::vector<int, std::allocator<int> >, std::vector<std::function<void (int)>, std::allocator<std::function<void (int)> > >), std::vector<int, std::allocator<int> >&, std::vector<std::function<void (int)>, std::allocator<std::function<void (int)> > >&>(void (&)(std::vector<int, std::allocator<int> >, std::vector<std::function<void (int)>, std::allocator<std::function<void (int)> > >), std::vector<int, std::allocator<int> >&, std::vector<std::function<void (int)>, std::allocator<std::function<void (int)> > >&)':
ThreadTest.cpp:(.text._ZNSt6threadC2IRFvSt6vectorIiSaIiEES1_ISt8functionIFviEESaIS6_EEEJRS3_RS8_EEEOT_DpOT0_[_ZNSt6threadC5IRFvSt6vectorIiSaIiEES1_ISt8functionIFviEESaIS6_EEEJRS3_RS8_EEEOT_DpOT0_]+0x39): undefined reference to `pthread_create'
/tmp/cc0NzGGt.o: In function `std::thread::thread<int (&)(int, int), std::reference_wrapper<int>, std::reference_wrapper<int> >(int (&)(int, int), std::reference_wrapper<int>&&, std::reference_wrapper<int>&&)':
ThreadTest.cpp:(.text._ZNSt6threadC2IRFiiiEJSt17reference_wrapperIiES4_EEEOT_DpOT0_[_ZNSt6threadC5IRFiiiEJSt17reference_wrapperIiES4_EEEOT_DpOT0_]+0x39): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status