0

I tried to compile program with https://github.com/yhirose/cpp-httplib "one-header" library. I wrote

#include "httplib.h"
/* example code from main github page */

and when i tried to compile program

g++ -std=c++11 -o test test.cc

i got this error:

/usr/bin/ld: /tmp/ccYMj4l8.o: in function `std::thread::thread<httplib::ThreadPool::worker, , void>(httplib::ThreadPool::worker&&)':
test.cc:(.text._ZNSt6threadC2IN7httplib10ThreadPool6workerEJEvEEOT_DpOT0_[_ZNSt6threadC5IN7httplib10ThreadPool6workerEJEvEEOT_DpOT0_]+0x2f): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status

What can i do? And how to link libraries that have include and src directories, e.g. libcurl

kocotian
  • 97
  • 1
  • 7
  • 1
    Does this answer your question? [Undefined reference to pthread\_create in Linux](https://stackoverflow.com/questions/1662909/undefined-reference-to-pthread-create-in-linux) – rveerd Jun 26 '20 at 13:53

1 Answers1

3

It's gcc's known particular feature, its std::thread implementation is built upon pthreads so it requires specifying -pthread to correctly link programs with threads.

bipll
  • 11,747
  • 1
  • 18
  • 32