cpr icon indicating copy to clipboard operation
cpr copied to clipboard

cpr.h includes windows.h on Windows (again)

Open cschreib-ibex opened this issue 2 years ago • 4 comments

See https://github.com/libcpr/cpr/issues/700 for the first bug report on this issue. It was fixed for a while, but unfortunately https://github.com/libcpr/cpr/commit/c0a412230be7ce1fced4b8c3a6fb2b8b9f7dd746 introduced a new inclusion of curl.h, so the problem appeared again.

Here's the chain:

  • cpr/cpr.h -> cpr/cookies.h -> cpr/curlholder.h -> curl/curl.h

Description

See https://github.com/libcpr/cpr/issues/700.

Expected Behavior

See https://github.com/libcpr/cpr/issues/700.

Actual Behavior

See https://github.com/libcpr/cpr/issues/700.

Possible Fix

See https://github.com/libcpr/cpr/issues/700.

Steps to Reproduce

See https://github.com/libcpr/cpr/issues/700.

Context

See https://github.com/libcpr/cpr/issues/700.

Your Environment

  • Version used: 1.8.1
  • Where did you get it from (e.g. conan, vcpkg, master, ...): conan
  • Operating System and version: Windows 10 Pro
  • Link to a small example:
void CopyFile() {  /*...*/ }

#include "cpr/cpr.h"

int main() {
    CopyFile(); // compiler error
}

cschreib-ibex avatar Jun 01 '22 15:06 cschreib-ibex

Thanks for the heads up on this one. I will have a look at it shortly!

COM8 avatar Jun 03 '22 08:06 COM8

I don't think this is something we can fix if you include cpr/cpr.h since we require the curl.h include inside cpr/curlholder.h for the CURL type, which is not being able to be forward declared.

I have created a PR to reduce the number of transitive curl.h includes in cpr here: https://github.com/libcpr/cpr/pull/758 Could you please try this branch and do not include cpr/cpr.h, but instead try cpr/api.h.

COM8 avatar Jun 08 '22 13:06 COM8

Ping @cschreib-ibex

COM8 avatar Jun 20 '22 11:06 COM8

Sorry, I was on honeymoon! I just gave it a go, and it seems there is still an issue:

  • cpr/api.h -> cpr/response.h -> cpr/ssl_options.h -> curl/curl.h It looks like the include to cpr/ssl_options.h can just be removed from response.h.

  • cpr/api.h -> cpr/session.h -> cpr/ssl_options.h -> curl/curl.h This one cannot just be removed. session.h needs forward declarations for

    struct VerifySsl;
    struct SslOptions;

Then there's a reference to the CURLcode type; I don't know if that can be forward-declared?

        Response Complete(CURLcode curl_error);

Alternatively, includes to ssl_options.h can remain unchanged, but some of the code inside ssl_options.h can be split out into a .cpp, so the header does not need to include curl.h.

cschreib-ibex avatar Jun 23 '22 14:06 cschreib-ibex