-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[ELF] Define NOMINMAX to fix zlib.h caused build failure on Windows #70368
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
Conversation
@llvm/pr-subscribers-lld-elf @llvm/pr-subscribers-lld Author: Yaxun (Sam) Liu (yxsamliu) ChangesOn Windows when zlib is enabled, zlib header introduced some C headers which defines max as a macro. Since OutputSections.cpp uses std::max with template argument, this causes compilation error. Undefine max to workaround this issue. Full diff: https://github.com/llvm/llvm-project/pull/70368.diff 1 Files Affected:
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 2dc425927109403..df78075fee6972e 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -23,6 +23,11 @@
#include "llvm/Support/TimeProfiler.h"
#if LLVM_ENABLE_ZLIB
#include <zlib.h>
+// zlib 1.2.13 causes max to be defined as a macro on Windows.
+// undefine it to use std::max.
+#ifdef max
+#undef max
+#endif
#endif
#if LLVM_ENABLE_ZSTD
#include <zstd.h>
|
I think zlib is often disabled on Windows, so nobody has noticed for such a long time.
Can you point out where |
62d09cb
to
e99c4af
Compare
zlib header does not define max as a macro, but it includes some windows headers which define max as macro. There is a cleaner way to avoid that by defining a macro NOMINMAX before include zlib.h. |
On Windows when zlib is enabled, zlib header introduced some Windows headers which defines max as a macro. Since OutputSections.cpp uses std::max with template argument, this causes compilation error. Define NOMINMAX before include zlib header to avoid introducing max as a macro.
e99c4af
to
27d713b
Compare
ping |
@@ -22,6 +22,8 @@ | |||
#include "llvm/Support/Path.h" | |||
#include "llvm/Support/TimeProfiler.h" | |||
#if LLVM_ENABLE_ZLIB | |||
// Avoid introducing max as a macro from Windows headers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Avoid introducing max as a macro from windows.h on Windows.
Thanks. The original title was not very clear. I have changed it to |
On Windows when zlib is enabled, zlib header introduced some Windows headers which defines max as a macro. Since OutputSections.cpp uses std::max with template argument, this causes compilation error.
Define macro NOMINMAX to avoid this.