3

我在这里按照构建说明进行操作:https ://github.com/Microsoft/cpprestsdk/wiki/How-to-build-for-Linux

#include <cpprest/http_client.h>
#include <cpprest/filestream.h>

using namespace utility;                    // Common utilities like string conversions
using namespace web;                        // Common features like URIs.
using namespace web::http;                  // Common HTTP functionality
using namespace web::http::client;          // HTTP client features
using namespace concurrency::streams;       // Asynchronous streams

int main(int argc, char* argv[])
{
    auto fileStream = std::make_shared<ostream>();

    // Open stream to output file.
    pplx::task<void> requestTask = fstream::open_ostream(U("results.html")).then([=](ostream outFile)
    {
        *fileStream = outFile;

        // Create http_client to send the request.
        http_client client(U("http://www.bing.com/"));

        // Build request URI and start the request.
        uri_builder builder(U("/search"));
        builder.append_query(U("q"), U("cpprestsdk github"));
        return client.request(methods::GET, builder.to_string());
    })

    // Handle response headers arriving.
    .then([=](http_response response)
    {
        printf("Received response status code:%u\n", response.status_code());

        // Write response body into the file.
        return response.body().read_to_end(fileStream->streambuf());
    })

    // Close the file stream.
    .then([=](size_t)
    {
        return fileStream->close();
    });

    // Wait for all the outstanding I/O to complete and handle any exceptions
    try
    {
        requestTask.wait();
    }
    catch (const std::exception &e)
    {
        printf("Error exception:%s\n", e.what());
    }

    return 0;
}

我编译g++ -std=c++11 castutorial.cpp -o castutorial -lboost_system -lcrypto -lssl -lcpprest

这是编译器错误消息:

/tmp/cck5DpD0.o: In function `main::{lambda(Concurrency::streams::basic_ostream<unsigned char>)#1}::operator()(Concurrency::streams::basic_ostream<unsigned char>) const':
castutorial.cpp:(.text+0x3c8): undefined reference to `web::http::client::http_client::~http_client()'
castutorial.cpp:(.text+0x48a): undefined reference to `web::http::client::http_client::~http_client()'
collect2: error: ld returned 1 exit status

如何找到 http_client.h 的实现?我阅读了有关链接器错误的信息。据我了解,目标文件或 lib 文件应该存在于某个地方,以便用我的程序进行编译。

4

0 回答 0