如何正确 link/include c++ 库

How to link/include c++ libraries correctly

我试图用https://github.com/yhirose/cpp-httplib“单头”库编译程序。我写了

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

当我尝试编译程序时

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

我收到这个错误:

/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

我能做什么? 以及如何 link 具有 includesrc 目录的库,例如libcurl

这是 gcc 的已知特殊功能,它的 std::thread 实现是基于 pthreads 构建的,因此它需要指定 -pthread 才能正确 link 带线程的程序。