runtime: Problem building on Arch Linux: min/max not defined
When trying to build the rc2 branch OR master on Arch Linux (clang 3.8) I get numerous build failures due to missing min and max macros.
Example:
mbstring.cpp:182:20: error: use of undeclared identifier 'min'
I’m assuming they are supposed to be defined in a platform include somewhere, and there is some voodoo I don’t understand happening between pal.h (where I see them defined) and palinternal.h that seems to be excluding your local copy. Or something. Sorry, I’m a bit out of my depth here, as I only know enough C++/C to get into trouble. 😃
Anyway, I was able to get things building by copying the defines for min and max from pal.h to palinternal.h. (above the include guard) I’m reasonably sure this was not the correct thing to do, even though it “worked,” but I’m not certain what is going wrong with the build configure process that causes this.
Hopefully I’ve given enough information here to identify what I might be doing wrong, or if maybe there is a problem with the build scripts.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 41 (18 by maintainers)
Commits related to this issue
- Don't use libstdc++ wrappers for stdlib.h This prevents #undef of min/max macros. Refs #5006. — committed to juergenhoetzel/coreclr by juergenhoetzel 8 years ago
- Don't use libstdc++ wrappers for stdlib.h This prevents #undef of min/max macros. Refs #5006. — committed to juergenhoetzel/coreclr by juergenhoetzel 8 years ago
- Don't use libstdc++ wrappers for stdlib.h (#5304) This prevents #undef of min/max macros. Refs #5006. — committed to dotnet/coreclr by juergenhoetzel 8 years ago
@mmitche, @sergiy-k, since CoreCLR is building on Arch Linux and passing all tests at this point (https://github.com/dotnet/coreclr/issues/5304 patch applied), can we get the CI job configured for Arch as well so it doesn’t regress?
min/max is not defined in the standard C Headers. It’s only defined in stdlibc++: http://www.cplusplus.com/reference/algorithm/max/
The libstdc++ devs actually undefine min/max to prevent conflicts
See
/PATH_TO_CPP_INCLUDES/bits/c++config.h:
You can check this using this C++ code:
results in
There is also Bugreport of #undef min/max is dependent on order if #include
The root cause of this problem is that recent versions of libstdc++ provide their own wrappers for stdlib.h:
Thus the GLIBC header /usr/include/stdlib.h (which didn’t undefine min/max) isn’t used anymore.
I added a woraround in my branch https://github.com/dotnet/coreclr/commit/7864b05cfcf16b1261962c5538e2f071759a1d9e
to restore the old behavior.
Seems Arch Linux is the first distro using GCC6. But this will also hit Fedora 24.