【问题标题】:how to properly install c++ cpr如何正确安装 c++ cpr
【发布时间】:2021-11-03 10:12:11
【问题描述】:

我需要安装 cpr,一个 c++ 库,但给我一些错误。
我试图包含从 github 下载的文件夹,但是当我尝试运行代码时,它给了我一个错误:

main.cpp:2:10: fatal error: cpr/cpr.h: No such file or directory
    2 | #include <cpr/cpr.h>
      |          ^~~~~~~~~~~
compilation terminated.

我的代码:

#include <iostream>
#include <cpr/cpr.h>
using namespace std;

int main() {
    cpr::Response r = cpr::Get(cpr::Url{"http://www.httpbin.org/get"},
    cpr::Parameters{{"hello", "world"}});
    cout << r.url << std::endl; // http://www.httpbin.org/get?hello=world
    cout << r.text << std::endl;
    return 0;
}

项目文件夹:

C:.
├───.vscode
└───cpr
    ├───.github
    │   └───workflows
    ├───cmake
    ├───cpr
    │   └───CMakeFiles
    │       └───3.21.2
    ├───include
    │   └───cpr
    └───test
        └───data

Visual Studio 代码通知我这个错误:

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (C:\Users\Bl4ckdestinyXX\Desktop\testcpp\main.cpp).

cannot open source file "curl/curlver.h" (dependency of "cpr/cpr.h")

我该如何解决?
PS:我是 C++ 新手
提前致谢

【问题讨论】:

标签: c++ httprequest httpwebrequest


【解决方案1】:

已经回复here

$ git clone https://github.com/whoshuu/cpr.git
$ cd cpr
$ mkdir build && cd build
$ cmake ..
$ make
$ sudo make install

【讨论】:

  • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。 - From Review
  • @acauã-pitta 对不起,我通常不回答问题,所以我真的不知道如何在此处正确格式化,我确实阅读了关于回答的 stackoverflow 指南,所以我确实包含了主要命令,谢谢!
猜你喜欢
  • 1970-01-01
  • 2015-11-23
  • 2014-10-22
  • 2021-11-15
  • 2011-10-11
  • 2014-09-16
  • 2021-01-17
  • 2011-08-19
  • 2016-12-09
相关资源
最近更新 更多