StephanTLavavej / mingw-distro

MinGW distro build scripts.
503 stars 58 forks source link

mingw-w64 6.0.0 doesn't consume its own headers correctly #64

Closed StephanTLavavej closed 3 years ago

StephanTLavavej commented 5 years ago

Building mingw-w64 6.0.0 fails with:

$ make $X_MAKE_JOBS all "CFLAGS=-s -O3"
make  all-recursive
Making all in mingw-w64-headers
make  all-am
make[3]: Entering directory '/c/temp/gcc/build-mingw-w64/mingw-w64-headers'
/usr/bin/sed s/MINGW_HAS_DX$/1/ ../../src/mingw-w64-headers/crt/sdks/_mingw_directx.h.in > _mingw_directx.h
make[3]: Leaving directory '/c/temp/gcc/build-mingw-w64/mingw-w64-headers'
make[3]: Entering directory '/c/temp/gcc/build-mingw-w64/mingw-w64-headers'
/usr/bin/sed s/MINGW_HAS_DDK$/1/ ../../src/mingw-w64-headers/crt/sdks/_mingw_ddk.h.in > _mingw_ddk.h
make[3]: Leaving directory '/c/temp/gcc/build-mingw-w64/mingw-w64-headers'
Making all in mingw-w64-crt
make[2]: Entering directory '/c/temp/gcc/build-mingw-w64/mingw-w64-crt'
[...]
gcc -DHAVE_CONFIG_H -I. -I../../src/mingw-w64-crt  -m64 -D__LIBMSVCRT__ -I../../src/mingw-w64-crt/include -I/c/temp/gcc/dest/x86_64-w64-mingw32/include  -pipe -std=gnu99 -D_CRTBLD -D_WIN32_WINNT=0x0f00 -D__MSVCRT_VERSION__=0x700 -Wall -Wextra -Wformat -Wstrict-aliasing -Wshadow -Wpacked -Winline -Wimplicit-function-declaration -Wmissing-noreturn -Wmissing-prototypes -s -O3 -MT misc/lib64_libcrtdll_a-onexit_table.o -MD -MP -MF misc/.deps/lib64_libcrtdll_a-onexit_table.Tpo -c -o misc/lib64_libcrtdll_a-onexit_table.o `test -f 'misc/onexit_table.c' || echo '../../src/mingw-w64-crt/'`misc/onexit_table.c
../../src/mingw-w64-crt/misc/onexit_table.c:15:38: error: unknown type name '_onexit_table_t'; did you mean '_onexit_t'?
 int __cdecl _initialize_onexit_table(_onexit_table_t *table)
                                      ^~~~~~~~~~~~~~~
                                      _onexit_t
[...]

The issue is that C:\Temp\gcc\src\mingw-w64-headers\crt\process.h now includes <corecrt_startup.h> which defines _onexit_table_t, but the compilation of src/mingw-w64-crt/misc/onexit_table.c isn't dragging in the updated process.h. (Instead, the current distro's process.h from mingw-w64 5.0.4 is being used.)

The Makefile is correctly building mingw-w64-headers before mingw-w64-crt, but it's not installing mingw-w64-headers before building mingw-w64-crt, so -I/c/temp/gcc/dest/x86_64-w64-mingw32/include isn't helping. (-I. -I../../src/mingw-w64-crt -I../../src/mingw-w64-crt/include can't help here.)

I'm working around this by building and installing mingw-w64-headers first, but this shouldn't be necessary. The mingw-w64-crt build should be fixed by adding -I options to consume headers from the source tree, instead of consuming whatever's in the current distro, or what's in the destination directory (usually, build and install aren't intermixed).

Note: This specific failure will seem to disappear after the distro is upgraded to mingw-w64 6.0.0 (via my workaround), as its process.h will no longer be outdated. However, the root cause will remain - updated headers in the source tree won't be consumed immediately, so when headers and sources simultaneously change (e.g. defining and using a new type like _onexit_table_t), this will happen again.

lhmouse commented 4 years ago

No. You install the headers before building everything else. This is part of the normal procedure of upgrading the CRT.

StephanTLavavej commented 4 years ago

Thanks for the info; I'll consider this a permanent change to my scripts and I'll close this issue during the next distro release. However, I will note that if the headers need to be built and installed first, then it makes no sense to have a combined build that doesn't do that step.