我正在学习cpp-netlib并试图运行官方网站上提供的exmaple客户端。代码非常简单:
#include <boost/network/protocol/http/client.hpp>
#include <iostream>
int main(int argc, char *argv[]) {
using namespace boost::network;
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " [url]" << std::endl;
return 1;
}
http::client client;
http::client::request request(argv[1]);
request << header("Connection", "close");
http::client::response response = client.get(request);
std::cout << body(response) << std::endl;
return 0;
}
这是我的c ++应用程序的makefile: CC = g ++ -std = c ++ 11
CFLAG = -I/usr/local/Cellar/boost/1.57.0/include
LIBFLAG = -L/usr/local/Cellar/boost/1.57.0/lib
all: client
client: client.o
$(CC) $(LIBFLAG) -lboost_system -lboost_thread client.o -o client
client.o: client.cpp
$(CC) -c $(CFLAG) client.cpp
clean:
rm -rf *.o client
它抱怨在编译后没有找到lboost_thread库:
ld: library not found for -lboost_thread
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [client] Error 1
在我的boost库目录中,boost_thread库显示如下:
libboost_thread-mt.a libboost_thread-mt.dylib
为什么它无法找到这个库?我在链接中犯了什么错误吗?
答案 0 :(得分:1)
尝试更改makefile以链接到-lboost-thread-mt而不是-lboost-thread。
由于某种原因,您似乎缺少libboost_thread