Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while trying to compile the hello world example on windows #1106

Open
PanAMD opened this issue Sep 6, 2024 · 1 comment
Open

Error while trying to compile the hello world example on windows #1106

PanAMD opened this issue Sep 6, 2024 · 1 comment

Comments

@PanAMD
Copy link

PanAMD commented Sep 6, 2024

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
@COM8
Copy link
Member

COM8 commented Sep 20, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants