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

minwindef.h min and max macros conflicting with std::numeric_limits #957

Open
nickbeth opened this issue Aug 23, 2023 · 1 comment · May be fixed by #1003
Open

minwindef.h min and max macros conflicting with std::numeric_limits #957

nickbeth opened this issue Aug 23, 2023 · 1 comment · May be fixed by #1003

Comments

@nickbeth
Copy link

Description

I'm using libcpr together with another library (glaze). In files where both are used (libcpr for requests and Glaze for JSON parsing of the response text), compilation is failing with the following error:

[...]/include\glaze/util/stoui64.hpp:14:54: error: too few arguments provided to function-like macro invocation
      return a <= std::numeric_limits<uint64_t>::max() - b;
                                                     ^
[...]\Windows Kits\10\Include\10.0.22621.0\shared\minwindef.h:193:9: note: macro 'max' defined here
#define max(a,b)            (((a) > (b)) ? (a) : (b))
        ^

If the two libraries are included in the following way, the above error appears:

#include <cpr/cpr.h>
#include <glaze/glaze.hpp>

By defining the NOMINMAX symbol before including the libcpr headers, the error disappears:

#define NOMINMAX
#include <cpr/cpr.h>
#include <glaze/glaze.hpp>

Inverting the include order also works:

#include <glaze/glaze.hpp>
#include <cpr/cpr.h>

Example/How to Reproduce

On Windows, include the libcpr headers before any code that uses std::numeric_limits::max() or std::numeric_limits::min().

Possible Fix

Define the NOMINMAX preprocessor symbol before including Windows headers in libcpr. As far as I've seen the min and max macros from minwindef.h are unused by libcpr.

Where did you get it from?

GitHub (branch e.g. master)

Additional Context/Your Environment

  • OS: Windows 11
  • Branch: 1.10.x
@mpate132
Copy link

@lynxnb the solution was really helpful since it is not worth it to change every file in the cpr and append the line#define NOMINMAX before the #include <windows.h>, so maybe it's better if we can just define other macro on our own in our project.

Your solution really helped me. Thanks

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

Successfully merging a pull request may close this issue.

2 participants