代码之家  ›  专栏  ›  技术社区  ›  Stiven Choking

在C++代码块中创建REST客户机?

  •  0
  • Stiven Choking  · 技术社区  · 6 年前

    我试图在CordBug编译器中创建C++中的REST API客户端。这就是为什么,我是 following this tutorial :

    #include <cpprest/http_listener.h>
    #include <cpprest/json.h>
    #pragma comment(lib, "cpprest110_1_1")
    
    using namespace web;
    using namespace web::http;
    using namespace web::http::experimental::listener;
    
    #include <iostream>
    #include <map>
    #include <set>
    #include <string>
    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;
    
    /* handlers implementation */
    
    int main()
    {
       http_listener listener(L"http://localhost/restdemo");
    
       listener.support(methods::GET, handle_get);
       listener.support(methods::POST, handle_post);
       listener.support(methods::PUT, handle_put);
       listener.support(methods::DEL, handle_del);
    
       try
       {
          listener
             .open()
             .then([&listener](){TRACE(L"\nstarting to listen\n");})
             .wait();
    
          while (true);
       }
       catch (exception const & e)
       {
          wcout << e.what() << endl;
       }
    
       return 0;
    }
    

    现在,当我要在代码块中摩擦cpp文件时,会出现以下错误:

    fatal error: cpprest/http_listener.h: No such file or directory

    如何解决此错误?你能给我一个链接吗?从哪里我可以想到在C++中创建REST API和REST客户机?

    1 回复  |  直到 6 年前
        1
  •  0
  •   Thomas Sablik    6 年前

    必须将路径添加到包含文件。例如,http_listener.h的路径是

    /a/b/cpprest/http_listener.h
    

    在代码块中打开项目->生成选项…->搜索目录。在tabcompiler中添加

    /a/b
    

    现在编译器将找到您的include。接下来,您必须在tab linker中设置链接器搜索路径 undefined reference .