cpr icon indicating copy to clipboard operation
cpr copied to clipboard

Error while trying to compile the hello world example on windows

Open PanAMD opened this issue 1 year ago • 1 comments

Description

I've been trying to compile the most basic "hello world" program for cpr but it keep getting the same errors regardless of the method that I use to include the cpr library. I'm using C++20 and the 1.10.x cpr branch

Errors that I'm getting:

error C2143: syntax error: missing ';' before '*' error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C2334: unexpected token(s) preceding '{'; skipping apparent function body error C2065: 'CURL_PROGRESSFUNC_CONTINUE': undeclared identifier error C3861: 'CURL_PROGRESSFUNC_CONTINUE': identifier not found

Things that I've tried:

  1. Compiling cpr using cmake: I've tried to build the library by myself using the following commands (I couldn't do cmake install because there seems to be another bug with that): cmake .. -DCPR_USE_SYSTEM_CURL=OFF -DBUILD_SHARED_LIBS=OFF cmake --build . --parallel
  2. Cloning the library directly using cmake include(FetchContent) FetchContent_Declare(cpr GIT_REPOSITORY https://github.com/libcpr/cpr.git GIT_TAG 3b15fa82ea74739b574d705fea44959b58142eb8) FetchContent_MakeAvailable(cpr)

Source code

#include <cpr/cpr.h>

int main() {

    cpr::Response r = cpr::Get(cpr::Url{url});

    if (r.status_code == 200) {
        try {
            // Parse the response as JSON
            nlohmann::json commits = nlohmann::json::parse(r.text);
            std::cout << commits.dump(4) << std::endl;  // Pretty-print the JSON response
        } catch (nlohmann::json::parse_error& e) {
            std::cerr << "JSON parse error: " << e.what() << std::endl;
        }
    } else {
        std::cerr << "HTTP error: " << r.status_code << std::endl;
    }
    return 0;
}

Example/How to Reproduce

  1. Clone the cpr repository using cmake
  2. Try to build the example code

Possible Fix

No response

Where did you get it from?

GitHub (branch e.g. master)

Additional Context/Your Environment

  • OS: Windows 10
  • Version: 10.0.19045.4780

PanAMD avatar Sep 06 '24 17:09 PanAMD

@PanAMD Can you please try the following example code: https://github.com/libcpr/example-cmake-fetch-content

COM8 avatar Sep 20 '24 15:09 COM8

Closing for no response.

COM8 avatar Nov 12 '24 19:11 COM8