我尝试用https://github.com/yhirose/cpp-httplib“one-header”库编译程序。 我写过
#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
我能做什么? 以及如何链接具有include
和src
目录的库,例如libcurl
这是GCC已知的特殊特性,它的std::thread
实现构建在pthreads之上,因此需要指定-pthread
才能正确地将程序与线程链接起来。