2017-01-20 26 views
0

由于关于REST服务学习过程的一部分,我想建立使用Microsoft Visual C++一个REST SDK“卡萨布兰卡”一个简单的HTTP侦听器。我最初的目标是测试它是否可以接收指向localhost的简单POST请求并将文本保存在文件中。链接器错误与卡萨布兰卡VS2015而试图建立一个简单的HTTP侦听

我在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 POST\n"); 

    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 listen\n"); }) 
      .wait(); 

     while (true); 
    } 
    catch (exception const & e) 
    { 
     wcout << e.what() << endl; 
    } 
} 

一个错误我得到的:

悬而未决在function_main中引用的外部符号“__declspec(dllimport)public:_thiscall web :: uri :: uri(wchar_t const *)”(__imp _ ?? 0uri @ web @@ QAE @ PB_W @ Z)

如果有人愿意,指出我在做什么错了

回答

0

您是否在链接器 - >输入中包含cpprest.lib作为您的其他依赖项。确切的名字取决于你是否正在做cpprest库的静态或动态链接。你

可能还需要添加_NO_ASYNCRTIMP预处理定义,如果你正在做静态链接。

希望这会有所帮助

相关问题