VS2015 中卡萨布兰卡的链接器错误,同时尝试构建一个简单的 HTTP 侦听器

Linker Errors with casablanca in VS2015 while trying to build a simple HTTP listener

本文关键字:构建 一个 侦听器 HTTP 简单 链接 卡萨布兰卡 错误 VS2015      更新时间:2023-10-16

作为学习Rest服务过程的一部分,我正在尝试使用Microsoft c ++ REST SDK"casablanca"构建一个简单的HTTP侦听器。我最初的目标是测试它是否可以接收指向本地主机的简单 POST 请求并将文本保存在文件中。

我正在VS2015上构建这个项目。我使用内置的包管理器来查找并安装 sdk,并从 github 下载了所需的头文件并将它们添加为额外的包含目录。尝试构建时,我不断收到错误代码LNK2019的"未解析的外部符号"错误

这是到目前为止的代码

#include <cpprest/http_listener.h>
#include <iostream>
#include <stdlib.h>
using namespace web;
using namespace web::http;
using namespace web::http::experimental::listener;
using namespace utility;
using namespace std;
#define TRACE(msg)            wcout << msg;
#define TRACE_ACTION(a, k, v) wcout << a << L" (" << k << L", " << v << L")n";
map<utility::string_t, utility::string_t> dictionary;

void handle_post(http_request request)
{
    TRACE(L"nhandle POSTn");
    utility::string_t input;
    input = request.to_string();
    utility::ofstream_t out("output.txt");
    out << input;
    out.close();
}
int main(int argc, char** argv)
{
    http_listener listener(L"http://localhost:8080");
    listener.support(methods::POST, handle_post);

    try
    {
        listener
             .open()
             .then([&listener]() {TRACE(L"nstarting to listenn"); })
             .wait();
         while (true);
    }
    catch (exception const & e)
    {
        wcout << e.what() << endl;
    }
}

我遇到的错误之一:

未解析的外部符号" __declspec(dllimport) public:_thiscall web::uri::uri(wchar_t const*)" (__imp_??0uri@web@@QAE@PB_W@Z) 在function_main中引用

如果有人能向我指出我做错了什么,将不胜感激

您是否

在Linker->Input中包含cpprest.lib作为其他依赖项。确切的名称取决于您是执行 cpprest 库的静态链接还是动态链接。

此外,如果要执行静态链接,则可能需要添加_NO_ASYNCRTIMP预处理器定义。

希望这有帮助