0

我正在学习 cpp-netlib 并尝试运行官方网站上给出的示例客户端。代码非常简单:

#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++ 应用程序的生成文件: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  

为什么找不到这个库?我在链接中犯了任何错误吗?

4

1 回答 1

1

尝试更改您的 makefile 以链接到 -lboost-thread-mt 而不是 -lboost-thread。

由于某种原因,您似乎缺少 libboost_thread

于 2015-05-17T03:27:28.760 回答