G
G
GrigorySvetov2018-07-20 21:34:20
C++ / C#
GrigorySvetov, 2018-07-20 21:34:20

Can't find std::threads. What's wrong?

C::B does not find thread. In the compilation settings (both project>>build options and settings>>compiler) I specified the use of C++14 (threads are allowed from C++11).
Code, for example, is:

#include <thread>
using namespace std;
void doIt(){
  //do nothing
}
int main(){
  thread t(doIt);
  t.detach();
  return 0;
}

What could be the snag? I understand that my question is probably stupid, but still we always start somewhere ...
PS In VS 2017 for some reason there is another problem ... "There is no such constructor that only a void function is in the parameters" . (Using C++14 is similarly prescribed)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2018-07-20
@jcmvbkbc

Can't find std::threads. What's wrong?

Who does not find? What is the error message?
I see this:
$ cat > thr.cpp
#include <thread>
using namespace std;
void doIt(){
  //do nothing
}
int main(){
  thread t(doIt);
  t.detach();
  return 0;
}
$ g++ -std=c++11 thr.cpp -o thr
/tmp/ccVyziLM.o: In function `std::thread::thread<void (&)()>(void (&)())':
thr.cpp:(.text._ZNSt6threadC2IRFvvEJEEEOT_DpOT0_[_ZNSt6threadC5IRFvvEJEEEOT_DpOT0_]+0x20): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status

It is treated with the -pthread key:
$ g++ -std=c++11 thr.cpp -pthread -o thr

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question