runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Problem building on Arch Linux: min/max not defined

Open tetious opened this issue 10 years ago • 41 comments

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.

tetious avatar May 17 '16 03:05 tetious

I have been able to build CoreClr on ArchLinux using clang 3.5. Could you try to use that version ? I will try to update it on my side to see if I have the same problem. Be aware that you wont be able to build mscorelib because of some post build step that download a cli package which was generate for ubuntu.

davzucky avatar May 17 '16 14:05 davzucky

@tetious - It seems that the macro definitions in the pal.h can be moved out of the #ifndef PAL_STDCPP_COMPAT and defined conditionally like this:

#ifndef max
#define max(a, b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif

I believe that should fix the issue.

janvorli avatar May 17 '16 14:05 janvorli

@davzucky I did try building with clang 3.5 and ran into the same problem. I'm pretty sure I tried it based on your mention of success elsewhere. Not sure why it worked for you and not me. :)

@janvorli That didn't seem to fix it. I'm not sure why. I even tried putting them outside the include guard. The only way I've been able to get a successful build is by putting them outside the include guard in palinternal.h.

Also, I needed to apply the fix here, which maybe could be cherry-picked into this branch? https://github.com/dotnet/coreclr/pull/4433

tetious avatar May 17 '16 14:05 tetious

@tetious, After updating my fork, I'm now getting the same problem as you. This is confusing as the save branch is working on Ubuntu. I'm not sure what could cause the problem and min max definition in palinternal doesnt sound right. I will try to go through all the change on the build script that could have trigger that for the past 2-3 weeks. Let me know if you find anything.

@janvorli, Any idea what could trigger this error on one distribution but not on other ? I know it use to work on the same machine before I rebase my fork which was old of ~2-3 weeks

davzucky avatar May 19 '16 05:05 davzucky

@davzucky, @tetious is it possible that the issue is not related to our source changes, but rather to some update of your Linux? E.g. that the min / max macros would be removed from some header files that we are including, possibly moved somewhere else? These macros are not required to exist by the C++ standard. Could you scan all headers on your Linux to see where (if at all) the macro is defined?

janvorli avatar May 19 '16 08:05 janvorli

For me, it's defined at 'coreclr/src/pal/inc/pal.h' file, line 6067

#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))

#endif // !PAL_STDCPP_COMPAT

and I think PAL_STDCPP_COMPAT is not defined for the build, but I can find them in some .cmake files.

seanshpark avatar May 19 '16 10:05 seanshpark

I am sorry for not being clear, I meant where is it defined in the system headers, not in our ones. The PAL_STDCPP_COMPAT is defined when building several components (debugger stuff / lttng stuff).

janvorli avatar May 19 '16 10:05 janvorli

Here is the result of a grep in /usr/include on my system:

./X11/Xlibint.h-
./X11/Xlibint.h:#define min(a,b) (((a) < (b)) ? (a) : (b))
./X11/Xlibint.h-#define max(a,b) (((a) > (b)) ? (a) : (b))
./X11/Xlibint.h-

./clang/Basic/SourceManager.h-/// Given an example of:
./clang/Basic/SourceManager.h-/// \code
./clang/Basic/SourceManager.h:/// #define min(x, y) x < y ? x : y
./clang/Basic/SourceManager.h-/// \endcode
./clang/Basic/SourceManager.h-///

./python2.7/TiffDecode.h-
./python2.7/TiffDecode.h-#ifndef min
./python2.7/TiffDecode.h:#define min(x,y) (( x > y ) ? y : x )
./python2.7/TiffDecode.h-#define max(x,y) (( x < y ) ? y : x )
./python2.7/TiffDecode.h-#endif

I think it is interesting that the only clang result is an example. :)

It does look like it isn't defined anywhere that would reasonably be included.

tetious avatar May 19 '16 11:05 tetious

Ok, so that would explain why it was not found if the PAL_STDCPP_COMPAT was not defined, since in that case, we don't try to define the min and max. So I wonder if you are hitting the error while building the components that have the PAL_STDCPP_COMPAT defined. Would you mind sharing the build log so that I can take a peek?

janvorli avatar May 19 '16 13:05 janvorli

@tetious and @janvorli, I think I found the root cause and as you say @Janvorli this is a system problem relate to the update of the gcc package on my system. As Linux is a rolling like type of system it can be hurd by this type of problem earlier. I ran the below command to downgrad gcc and gcc-lib from 6.1.1.1 to 5.3.0.5 and I'm now able to build again.

sudo pacman -U https://archive.archlinux.org/packages/g/gcc/gcc-5.3.0-5-x86_64.pkg.tar.xz https://archive.archlinux.org/packages/g/gcc-libs/gcc-libs-5.3.0-5-x86_64.pkg.tar.xz

I will have to look at what is the delta in these packages tomorrow to see what got broken. @tetious, Could you try to downgrade the library as well to confirm it's working as well for you ?

davzucky avatar May 20 '16 14:05 davzucky

BTW, I had as well to downgrade LLVM to get it working as the new version is build against GCC 6. Run this command as well

sudo pacman -U https://archive.archlinux.org/packages/l/llvm/llvm-3.7.1-1-x86_64.pkg.tar.xz https://archive.archlinux.org/packages/l/llvm-libs/llvm-libs-3.7.1-1-x86_64.pkg.tar.xz

my build still hasn't finished but it's moving forward :-). need to find what change in GCC

davzucky avatar May 20 '16 14:05 davzucky

@juergenhoetzel, @vindicatorr, did you guys experience this error?

ghost avatar May 23 '16 01:05 ghost

Downgrading gcc, gcclibs and llvm didn't work for me. The suggestion of @janvorli didn't work for me. But after adding that (*) to palinternal.h the compile seem to work fine.

(*) #ifndef max #define max(a, b) (((a) > (b)) ? (a) : (b)) #endif #ifndef min #define min(a, b) (((a) < (b)) ? (a) : (b)) #endif

#https://github.com/elangelo/coreclr/tree/pal

elangelo avatar May 24 '16 12:05 elangelo

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:

// For example, <windows.h> is known to #define min and max as macros...
#undef min
#undef max

You can check this using this C++ code:

#define max( a, b ) (((a) > (b)) ? (a) : (b))
#include <iostream>
int main(int argc, char **argv)  {
std::cout << max(1,2) << std::endl;
}

results in

/tmp/test.cc:4:15: error: use of undeclared identifier 'max'; did you mean 'std::max'?
        std::cout << max(1,2) << std::endl;
                     ^~~
                     std::max

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.

juergenhoetzel avatar May 27 '16 16:05 juergenhoetzel

@jasonwilliams200OK I was out of town, but was just about to do a full rebuild for a different corefx bug and encountered this issue. (posted on gitter)

[  1%] Building CXX object src/pal/src/CMakeFiles/coreclrpal.dir/cruntime/mbstring.cpp.o
.../tmp/source/coreclrarch/src/pal/src/cruntime/mbstring.cpp:182:20: error: use of undeclared identifier 'min'
            ret += min(count, strlen((const char*)string));
                   ^
1 error generated.
src/pal/src/CMakeFiles/coreclrpal.dir/build.make:182: recipe for target 'src/pal/src/CMakeFiles/coreclrpal.dir/cruntime/mbstring.cpp.o' failed
make[2]: *** [src/pal/src/CMakeFiles/coreclrpal.dir/cruntime/mbstring.cpp.o] Error 1
CMakeFiles/Makefile2:241: recipe for target 'src/pal/src/CMakeFiles/coreclrpal.dir/all' failed
make[1]: *** [src/pal/src/CMakeFiles/coreclrpal.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[  1%] Building CXX object src/corefx/System.Globalization.Native/CMakeFiles/System.Globalization.Native.dir/normalization.cpp.o

vindicatorr avatar May 28 '16 04:05 vindicatorr

I was able to build on Arch Linux (clang3.5 + clang3.8) using my workaround: https://github.com/dotnet/coreclr/issues/5006#issuecomment-222191925

I just updated my branch (there was an invalid CPP-conditional).

juergenhoetzel avatar May 28 '16 07:05 juergenhoetzel

Thanks for the fix @judemelancon! Can you send a pull request so this matter is resolved once and for all. :)

ghost avatar May 28 '16 08:05 ghost

@jasonwilliams200OK @juergenhoetzel This is just to make sure your conversation isn't derailed by that overzealous autocompletion.

judemelancon avatar May 28 '16 12:05 judemelancon

I'm pretty sure I've done some cherry-picking once or twice before, but maybe I'm doing it wrong now because I get "fatal: bad object 7864b05cfcf16b1261962c5538e2f071759a1d9e"

I'm on coreclr's master branch and just trying a simple "git cherry-pick 786...", even after cleaning, resetting, fetching and pulling. I must be missing something.

vindicatorr avatar May 28 '16 15:05 vindicatorr

@judemelancon, sorry I meant to @ juergenhoetzel. :smile:

ghost avatar May 28 '16 15:05 ghost