0

i need to install cpr, a library for c++, but give me some errors.
I have tried to include the downloaded folder from github, but when I try to run the code, it give me an error:

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

My code:

#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;
}

Project folders:

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

Visual studio code notice me of this errors:

#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")

How i can fix that?
PS: I'm new to C++
Thanks in advance

BlackdestinyXX
  • 331
  • 3
  • 17
  • You need to actually build and install the cpr library somewhere before you can use it, and then you need to tell your compiler where to look for the headers to cpr when you compile your project. – Botje Sep 06 '21 at 09:55

1 Answers1

2

Has already been answered here

$ git clone https://github.com/whoshuu/cpr.git
$ cd cpr
$ mkdir build && cd build
$ cmake ..
$ make
$ sudo make install
Evertiro
  • 779
  • 6
  • 24
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/30500304) – Acauã Pitta Dec 06 '21 at 18:09
  • @acauã-pitta Sorry I don't usually answer questions so I didn't really know how to format it here correctly, I did read the stackoverflow guides on answering so I did include the main commands, Thank you! – Vaibhav Dhiman Dec 08 '21 at 13:04