How to use the CPR library in c++?

感情迁移 提交于 2021-01-28 05:40:32

问题


I was previously developing in python and now I've switched to C++. I found a cool library called CPR https://github.com/whoshuu/cpr that can be used to make HTTP requests easily like python requests. Like in python there are no easy pkg managers like pip to install libraries in C++. How can I use cpr in my project. There are no dlls or lib file in that.


回答1:


c++ packages are usually distributed as a set of development headers and static/shared libraries. However in the case of cpr, the documentation recommends to use submodules to get the functionality into your project.

As cpr uses cmake, I would also expect this to be possible (although not documented):

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

Then cpr will be available in your system (as long as make install copies the built libraries and development headers to system-wide location). In your project, you will be able to include cpr like so:

#include <cpr/cpr.h>

And build it like so:

g++ -std=c++11 -o main -lcpr main.cpp



回答2:


You can always try old-ways and use header files directly. Most likely, under the hood it all comes down to some call like "gcc ......." and to get an idea of how to put together the proper build list for cpr try looking at their travis.yml https://github.com/whoshuu/cpr/blob/master/.travis.yml or how their Cmake calls are made.

You need CPR



来源:https://stackoverflow.com/questions/58362204/how-to-use-the-cpr-library-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!