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

Add -DNOMINMAX compiler definition for Windows #1054

Closed
wants to merge 1 commit into from

Conversation

jacobperron
Copy link
Member

@jacobperron jacobperron commented Apr 9, 2020

This fixes an issue where max() and min() are treated as macros defined in windows.h

Alternative to #1053

Windows: Build Status

This fixes an issue where max() and min() are treated as macros defined in windows.h

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
@wjwwood
Copy link
Member

wjwwood commented Apr 9, 2020

I think this is also ok to do, but there are cases where people do want the min/max macros, e.g.:

https://developercommunity.visualstudio.com/content/problem/114149/gdiplush-does-not-compile-when-nominmax-is-defined.html

Also, unless we export that definition it will not work when someone trys to use our headers (without adding the compiler definition themselves).

@jacobperron
Copy link
Member Author

Also, unless we export that definition it will not work when someone trys to use our headers (without adding the compiler definition themselves).

I did not want to export the definition. I made this change assuming that we don't want to use the min/max macros in the rclcpp packages. Users can still use them if they want, and will have to workaround our definitions if they happen to include the macros before our headers.

Copy link
Contributor

@Karsten1987 Karsten1987 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach

@dirk-thomas
Copy link
Member

Since this is not necessary anymore and wouldn't prevent downstream packages to fail I don't think this should be merged.

@jacobperron
Copy link
Member Author

I see it as defensive. We're currently relying on external packages (e.g. rcutils) to not include Windows.h or have them define NOMINMAX for us. Knowing that we use max() and min() in rclcpp packages, this change avoids accidental breaks due to upstream packages introducing the Windows macros.

@dirk-thomas
Copy link
Member

If any dependency introduces such an include this patch I would expect the patch to only work around the problem when building this package but downstream code would still fail to build, right?

@jacobperron
Copy link
Member Author

If any dependency introduces such an include this patch I would expect the patch to only work around the problem when building this package but downstream code would still fail to build, right?

That's right, I was only trying to ensure that this package builds. In retrospect, maybe not a great patch considering it might be better for us to avoid shipping a "broken" rclcpp accidentally.

@clalancette clalancette deleted the jacob/avoid_max_min-2 branch January 15, 2021 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants