提问者:小点点

如何正确链接/包含C++库


我尝试用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

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


共1个答案

匿名用户

这是GCC已知的特殊特性,它的std::thread实现构建在pthreads之上,因此需要指定-pthread才能正确地将程序与线程链接起来。

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(链接|包含|c++|库)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?