When crossing from GNU/Linux to MinGW, I can successfully build cross binutils, cross gcc, and crossed-native gcc, but doing so requires a number of individual hacks, none of which I think should be necessary. (Building cross binutils requires no hacks - this is not a binutils bug.) cross.sh which I run on GNU/Linux: #!/bin/sh echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ echo @ Initializing script. echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ read dummy CROSS_ROOT=/home/stl/cross BU_SRC=$CROSS_ROOT/binutils-src BU_BUILD=$CROSS_ROOT/binutils-build XGCC_SRC=$CROSS_ROOT/xgcc-src XGCC_BUILD=$CROSS_ROOT/xgcc-build XGCC_DEST=$CROSS_ROOT/xgcc-dest WINGCC_SRC=$CROSS_ROOT/wingcc-src WINGCC_BUILD=$CROSS_ROOT/wingcc-build WINGCC_DEST=$CROSS_ROOT/wingcc-dest CONFIGURY1='--build=i686-pc-linux-gnu --target=mingw32 --enable- languages=c,c++' CONFIGURY2='--disable-nls --disable-debug --disable-shared --disable-win32- registry' CONFIGURY3='--without-newlib --enable-threads=win32 --enable-sjlj-exceptions' CONFIGURY4='--with-gnu-as --with-gnu-ld --with-gcc' export CC=gcc export CXX=g++ export AS=as export LD=ld export AR=ar export CFLAGS='-O3 -fomit-frame-pointer -ffast-math' export CXXFLAGS=$CFLAGS export LIBCFLAGS=$CFLAGS export LIBCXXFLAGS=$CFLAGS export BOOT_CFLAGS=$CFLAGS export LDFLAGS='-s' mkdir -p $BU_BUILD $XGCC_BUILD $XGCC_DEST/mingw32 $WINGCC_BUILD \ $WINGCC_DEST/mingw32 $WINGCC_DEST/include cd $CROSS_ROOT echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ echo @ Dump mingw-runtime-3.2.tar and w32api-2.5.tar into CROSS_ROOT. echo @ They must be binaries that extract to bin, include, lib. echo @ echo @ Dump gcc-3.3.3-truemingw.tar into CROSS_ROOT. echo @ It must be source that extracts to gcc-3.3.3-truemingw. echo @ echo @ Dump binutils-2.15.90-20040222-1-src.tar into CROSS_ROOT. echo @ It must be source that extracts to binutils-2.15.90-20040222-1. echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ read dummy echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ echo @ Extracting. echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ read dummy tar xf mingw-runtime-3.2.tar -C $XGCC_DEST/mingw32 tar xf w32api-2.5.tar -C $XGCC_DEST/mingw32 tar xf mingw-runtime-3.2.tar -C $WINGCC_DEST/mingw32 tar xf w32api-2.5.tar -C $WINGCC_DEST/mingw32 tar xf gcc-3.3.3-truemingw.tar echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ echo @ Hacking. echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ read dummy mkdir -p $CROSS_ROOT/gcc-3.3.3-truemingw/libstdc++-v3/config/config/os/newlib cp $CROSS_ROOT/gcc-3.3.3-truemingw/libstdc++-v3/config/os/mingw32/* \ $CROSS_ROOT/gcc-3.3.3-truemingw/libstdc++-v3/config/config/os/newlib echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ echo @ Hacking. echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ read dummy cd $CROSS_ROOT/gcc-3.3.3-truemingw patch -p1 < $CROSS_ROOT/crossfix.patch cd $CROSS_ROOT echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ echo @ Extracting. echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ read dummy cp -r gcc-3.3.3-truemingw $XGCC_SRC mv gcc-3.3.3-truemingw $WINGCC_SRC tar xf binutils-2.15.90-20040222-1-src.tar mv binutils-2.15.90-20040222-1 $BU_SRC chmod 700 $BU_SRC/configure $XGCC_SRC/configure $WINGCC_SRC/configure echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ echo @ Configuring binutils. echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ read dummy cd $BU_BUILD $BU_SRC/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu \ --target=mingw32 --prefix=$XGCC_DEST --disable-nls --disable-shared \ --disable-debug --enable-threads=win32 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ echo @ Making binutils. echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ read dummy make echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ echo @ Installing binutils. echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ read dummy make install echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ echo @ Configuring xgcc. echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ read dummy export PATH=$XGCC_DEST/bin:$PATH cd $XGCC_BUILD $XGCC_SRC/configure --prefix=$XGCC_DEST --host=i686-pc-linux-gnu \ $CONFIGURY1 $CONFIGURY2 $CONFIGURY3 $CONFIGURY4 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ echo @ Making xgcc. echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ read dummy make echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ echo @ Installing xgcc. echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ read dummy make install echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ echo @ Configuring wingcc. echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ read dummy export CC=$XGCC_DEST/bin/mingw32-gcc export CXX=$XGCC_DEST/bin/mingw32-g++ export AS=$XGCC_DEST/bin/mingw32-as export LD=$XGCC_DEST/bin/mingw32-ld export AR=$XGCC_DEST/bin/mingw32-ar export LDFLAGS='-s -Wl,--stack=0x00800000' cd $WINGCC_BUILD $WINGCC_SRC/configure --prefix=$WINGCC_DEST --host=mingw32 --with-as=$AS \ --with-ld=$LD $CONFIGURY1 $CONFIGURY2 $CONFIGURY3 $CONFIGURY4 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ echo @ Hacking. echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ read dummy cp $WINGCC_BUILD/gcc/auto-host.h $WINGCC_BUILD/gcc/auto-build.h echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ echo @ Making wingcc. echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ read dummy make echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ echo @ Installing wingcc. echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ read dummy make install echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ echo @ Finished! The final product is in WINGCC_DEST. echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ See the notes that say "Hacking." If the first hack is not performed, building the cross gcc fails with a complaint about missing headers. If the second hack, which uses crossfix.patch: diff -aur gcc-3.3.3-truemingw/libstdc++-v3/include/bits/char_traits.h gcc- 3.3.3-truemingw-new/libstdc++-v3/include/bits/char_traits.h --- gcc-3.3.3-truemingw/libstdc++-v3/include/bits/char_traits.h 2003-10-07 18:15:05.000000000 -0700 +++ gcc-3.3.3-truemingw-new/libstdc++-v3/include/bits/char_traits.h 2004- 03-19 20:26:29.000000000 -0800 @@ -181,7 +181,7 @@ }; -#if defined (_GLIBCPP_USE_WCHAR_T) || defined (_GLIBCPP_USE_WSTRING) +#if 0 /// 21.1.3.2 char_traits specializations template<> struct char_traits<wchar_t> is not performed, building the cross gcc fails with a complaint about missing functions. See http://gcc.gnu.org/ml/gcc/2004-03/msg01182.html , where Gabriel Dos Reis says, > As you probably know, in the nutshell, native builds on MinGW or > Cygwin do not have support for wchar_t so correponding support in > libstdc++ is disabled. It looks like when building the cross, you did > -not- take that fact into consideration and somehow requested support > for wchar_t while the underlying C functions are missing. I didn't request any such support (you can see the configure lines right there), so something in gcc is misbehaving. The later suggestion to configure with --disable-c-mbchar did not affect the problem, only the #if 0 eliminated it. If the third hack is not performed, building the crossed-native fails with a complaint about "no rule to make auto-build.h". By looking into the configure scripts, I guessed that auto-build.h was a copy of auto-host.h. Finally, a fourth hack: cp $WINGCC_DEST/mingw32/lib/crt2.o $WINGCC_DEST/lib/gcc- lib/mingw32/3.3.3/crt2.o is necessary, otherwise crt2.o cannot be found when compiling C or C++ programs. All of these hacks seem to work, but I'd feel a lot better if they were not necessary. I don't remember having to perform any of these hacks when crossing the 3.3 I currently use (in particular I know I didn't have to do the fourth one), so these are probably all regressions.
For the first part, it is a configure bug, can you attach the config.log for libstdc++?
Created attachment 5953 [details] $XGCC_BUILD/gcc/config.log
That is the wrong config.log, the one I would like is in $XGCC_BUILD/mingw32-*/libstdc++.
Created attachment 5954 [details] $XGCC_BUILD/mingw32/libstdc++-v3/config.log
The first and second problem is in libstdc++'s configure.in (also in crossconfig.m4 on the 3.4 branch and the mainline): *-mingw32*) AC_CHECK_HEADERS([sys/types.h locale.h float.h]) GLIBCXX_CHECK_LINKER_FEATURES GLIBCXX_CHECK_COMPLEX_MATH_SUPPORT GLIBCXX_CHECK_WCHAR_T_SUPPORT It does not match the target which you used. The first and second problem can be worked around by instead using i686-mingw32 or i386-mingw32 instead. The thrid might be solved by doing the same also but I do not know.
If I use i686-pc-mingw32 instead of mingw32, and remove the hacks, making the cross gcc fails with: make[3]: Leaving directory `/home/stl/cross/xgcc-build/i686-pc- mingw32/libstdc++-v3' Making all in include make[3]: Entering directory `/home/stl/cross/xgcc-build/i686-pc- mingw32/libstdc++-v3/include' sed -e '/^#/s/\([ABCDEFGHIJKLMNOPQRSTUVWXYZ_][ABCDEFGHIJKLMNOPQRSTUVWXYZ_] *\)/_GLIBCPP_\1/g' \ -e 's,^#include "\(.*\)",#include <bits/\1>,g' \ < /home/stl/cross/xgcc-src/libstdc++-v3/../gcc/gthr.h > i686-pc- mingw32/bits/gthr.h sed -e 's/\(UNUSED\)/_GLIBCPP_\1/g' \ -e 's/\(GCC[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*_H\)/_GLIBCPP_\1/g' \ < /home/stl/cross/xgcc-src/libstdc++-v3/../gcc/gthr-single.h > i686-pc- mingw32/bits/gthr-single.h sed -e 's/\(UNUSED\)/_GLIBCPP_\1/g' \ -e 's/\(GCC[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*_H\)/_GLIBCPP_\1/g' \ -e 's/\([ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*WEAK\)/_GLIBCPP_\1/g' \ < /home/stl/cross/xgcc-src/libstdc++-v3/../gcc/gthr-posix.h > i686-pc- mingw32/bits/gthr-posix.h sed -e 's/\(UNUSED\)/_GLIBCPP_\1/g' \ -e 's/\(GCC[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*_H\)/_GLIBCPP_\1/g' \ -e 's/\([ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*WEAK\)/_GLIBCPP_\1/g' \ -e 's,^#include "\(.*\)",#include <bits/\1>,g' \ < /home/stl/cross/xgcc-src/libstdc++-v3/../gcc/gthr-win32.h > i686-pc- mingw32/bits/gthr-default.h make[3]: *** No rule to make target `/home/stl/cross/xgcc-src/libstdc++- v3/config/config/os/newlib/ctype_base.h', needed by `stamp-target'. Stop. make[3]: Leaving directory `/home/stl/cross/xgcc-build/i686-pc- mingw32/libstdc++-v3/include' make[2]: *** [all-recursive] Error 1 make[2]: Leaving directory `/home/stl/cross/xgcc-build/i686-pc- mingw32/libstdc++-v3' make[1]: *** [all-recursive-am] Error 2 make[1]: Leaving directory `/home/stl/cross/xgcc-build/i686-pc- mingw32/libstdc++-v3' make: *** [all-target-libstdc++-v3] Error 2 So it looks like this does NOT affect the need for the first hack.
Created attachment 5955 [details] $XGCC_BUILD/i686-pc-mingw32/libstdc++-v3/config.log
I should add that dllcrt2.o needs to be copied too in the fourth hack, otherwise DLLs can't be created. As an experiment, I executed -print-search-dirs with bootstrapped vs. crossed 3.3.3. I replaced the directory that the compiler lives in with WHATEVER/. Tidying things up a bit (leaving out "install:" which is apparently irrelevant, eliminating non-existent directories, etc.), I get: [CROSS] programs: WHATEVER/lib/gcc-lib/mingw32/3.3.3/ WHATEVER/lib/gcc-lib/ WHATEVER/mingw32/bin/mingw32/3.3.3/ WHATEVER/mingw32/bin/ libraries: WHATEVER/lib/gcc-lib/mingw32/3.3.3/ WHATEVER/lib/gcc-lib/ WHATEVER/mingw32/lib/mingw32/3.3.3/ WHATEVER/mingw32/lib/ [BOOTSTRAP] programs: WHATEVER/lib/gcc-lib/i686-pc-mingw32/3.3.3/ WHATEVER/lib/gcc-lib/ WHATEVER/i686-pc-mingw32/bin/i686-pc-mingw32/3.3.3/ WHATEVER/i686-pc-mingw32/bin/ libraries: WHATEVER/lib/gcc-lib/i686-pc-mingw32/3.3.3/ WHATEVER/lib/gcc-lib/ WHATEVER/i686-pc-mingw32/lib/i686-pc-mingw32/3.3.3/ WHATEVER/i686-pc-mingw32/lib/ WHATEVER/lib/i686-pc-mingw32/3.3.3/ WHATEVER/lib/ The cross was made with a target of mingw32 instead of i686-pc-mingw32, but that is irrelevant here. Note that the bootstrap has an extra directory in the "libraries:" which is not present for the cross: WHATEVER/lib/ crt2.o and dllcrt2.o live here. If the cross had this directory too, I bet the fourth hack would not be necessary. The crossed 3.3.3 still manages to find WHATEVER/lib/libFOO.a when -lFOO is given.
Hmm. Could you try running your build with *just C* and seeing which hacks are still needed? That would help diagnose which of the problems are specific to building target libraries and which aren't. Then, could you try a build with C & f77 -- this would show problems which show up in 'all' target libraries vs. ones which show up only in libstdc++.
[Nathanael C. Nerode] > Could you try running your build with *just C* and seeing which hacks > are still needed? Doing so now. The first and second hacks are obviously specific to C++. I have commented out the third and fourth hacks; I'll see if the build fails. Due to having found a way to work around PR14601, this bug is no longer a priority for me; I don't mind if the Powers decide to close it as WONTFIX, since building a bootstrap is easier than building a crossed native. On the other hand, I don't mind if this bug gets fixed. :-> > Then, could you try a build with C & f77 -- this would show problems which > show up in 'all' target libraries vs. ones which show up only in libstdc++. Okay, I can try this (I see your reasoning).
Hack 1 - Specific to libstdc++. Hack 2 - Specific to libstdc++. Hack 3 - Not target library specific. (Occurs when just C is used.) Crossing again to check out Hack 4.
The fourth hack is also not target library specific, so I will not perform the C and F77 build.
Thanks for your feedback; I'm going to try to fix the problems which occur C-only *first*, which means that I'm sort of going back-to-front. :-) The file auto-build.h is supposed to be constructed by gcc/configure for crossed natives. So could you please run a build up to and including this point, and then stop: $WINGCC_SRC/configure --prefix=$WINGCC_DEST --host=mingw32 --with-as=$AS \ --with-ld=$LD $CONFIGURY1 $CONFIGURY2 $CONFIGURY3 $CONFIGURY4 Next, run 'make configure-gcc' if necessary to get files in the $WINGCC_BUILD/gcc directory (I think it is). Then if you could tar up the contents of $WINGCC_BUILD/gcc, I could try to figure out why auto-build.h isn't getting made (and where it's failing). (BTW, this is CVS HEAD, right?...)
Subject: Re: Crossing from GNU/Linux to MinGW requires SEVERAL hacks I was just able to walk through an approximation of this script using gcc mainline, and I was able to build the native ming32 compiler on GNU/Linux without requiring any hacks at all. So this may be fixed on mainline.
Nat, Stephan, what's the status on this bug? Are the required modifications already in HEAD? Stephan, can you test what is the situation at the moment? If the required hacks are only libstdc++ specific at this point, I can change the component and let the v3 maintainers take care of this.
(Massively delayed update.) I haven't built MinGW by crossing it from GNU/Linux in ages, and I no longer have the time to figure out what went wrong here. I now build MinGW natively with profiledbootstrap, which is way more convenient. This bug can be resolved WONTFIX.
Cross-building for mingw32 now works for me, and this bug has been inactive long enough that we can close it. If someone has recent data on this, please reopen!