MinGW-w64-GCC-14.2.0

Introduction to MinGW-w64-GCC

MinGW-w64-GCC has been built statically beforehand, and it should be rebuilt to ensure robustness. This section will be dedicated to finishing the MinGW-w64 toolchain.

MinGW-w64-GCC Dependencies

Required

MinGW-w64-12.0.0

Optional

GDB and Valgrind (for tests)

[Note]

Note

This may take a while to build. Feel free to do something else while this is building.

Installation of MinGW-w64-GCC

[Important]

Important

Although you are compiling for another host and running make install is generally safe, it is recommended to not run make install until you are confident the build was successful.

x86_64 Installation of MinGW-w64-GCC

Install x86_64 MinGW-w64-GCC by running the following commands:

mkdir build-x86_64-mingw-w64 &&
cd    build-x86_64-mingw-w64 &&

../configure                             \
    --prefix=/usr                        \
    --target=x86_64-w64-mingw32          \
    --enable-threads=posix               \
    --enable-shared                      \
    --disable-multilib                   \
    --enable-languages=c,c++ &&

make

If you have installed additional packages such as valgrind and gdb , the gcc part of the test suite will run more tests than in LFS. Some of those will report FAIL and others XPASS (pass when expected to FAIL). As of gcc-14.2.0, about 65 FAIL occur in the “guality” suite, as well as miscellaneous failures throughout the rest of the test suite. If all the compilers above are built, there will be a little over 80 unexpected failures out of over 546,000 tests. To run the tests, issue:

ulimit -s 32768 &&
make -k check

The tests are very long, and the results may be hard to find in the logs, specially if you use parallel jobs with make. You can get a summary of the tests with:

../contrib/test_summary

Now, as the root user:

make install &&

ln -sfv x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-cc &&
strip /usr/libexec/gcc/x86_64-w64-mingw32/14.2.0/{cc1*,collect2,lto*}

i686 Installation of MinGW-w64-GCC

Install i686 MinGW-w64-GCC by running the following commands:

mkdir build-i686-mingw-w64 &&
cd    build-i686-mingw-w64 &&

../configure                             \
    --prefix=/usr                        \
    --target=i686-w64-mingw32            \
    --enable-shared                      \
    --enable-threads=posix               \
    --disable-multilib                   \
    --enable-languages=c,c++ &&

make

If you have installed additional packages such as valgrind and gdb , the gcc part of the test suite will run more tests than in LFS. Some of those will report FAIL and others XPASS (pass when expected to FAIL). As of gcc-14.2.0, about 65 FAIL occur in the “guality” suite, as well as miscellaneous failures throughout the rest of the test suite. If all the compilers above are built, there will be a little over 80 unexpected failures out of over 546,000 tests. To run the tests, issue:

ulimit -s 32768 &&
make -k check

The tests are very long, and the results may be hard to find in the logs, specially if you use parallel jobs with make. You can get a summary of the tests with:

../contrib/test_summary

Now, as the root user:

make install &&

ln -sfv i686-w64-mingw32-gcc /usr/bin/i686-w64-mingw32-cc &&
strip /usr/libexec/gcc/i686-w64-mingw32/14.2.0/{cc1*,collect2,lto*}

Cleaning Up and Testing

Now that MinGW-w64-GCC and friends have been installed, it is time to test the MinGW-w64 installation to make sure everything is working as expected.

Confirm that the regular C and C++ compilers are working correctly:

echo "int main(){}" >> main.c &&
cp -v main.c main.cpp &&
gcc main.c            &&
./a.out               &&

rm -v a.out           &&
g++ main.cpp          &&
./a.out               &&

rm -v a.out main.{c,cpp}

If you're doing multilib:

echo "int main(){}" >> main.c &&
cp -v main.c main.cpp &&
gcc -m32 main.c       &&
./a.out               &&

rm -v a.out           &&
g++ -m32 main.cpp     &&
./a.out               &&

rm -v a.out main.{c,cpp}

Test the GNAT compiler:

cat >> testgnat.adb << "EOF" &&
with Ada.Text_IO; use Ada.Text_IO;
procedure Testgnat is
begin
   Put_Line("Success!");
end Testgnat;
EOF

gnatmake testgnat.adb &&
./testgnat            &&

rm -v testgnat*

Now test the MinGW-w64 cross compiler.

For x86_64:

cat >> main.c << "EOF"     &&
#include <stdio.h>
int main(){}
EOF

cp main.{c,cpp}                        &&
sed -i 's/stdio.h/iostream/g' main.cpp &&

x86_64-w64-mingw32-gcc main.c   &&
rm -v a.exe                     &&
x86_64-w64-mingw32-g++ main.cpp &&
rm -v a.exe main.{c,cpp}

For i686:

cat >> main.c << "EOF"     &&
#include <stdio.h>
int main(){}
EOF

cp main.{c,cpp}                        &&
sed -i 's/stdio.h/iostream/g' main.cpp &&

i686-w64-mingw32-gcc main.c            &&
rm -v a.exe                            &&
i686-w64-mingw32-g++ main.cpp          &&
rm -v a.exe main.{c,cpp}

The commands above should have no errors, otherwise something went wrong with the installation.

Command Explanations

mkdir build; cd build: The GCC documentation recommends building the package in a dedicated build directory.

--enable-shared: This option enables building shared libraries.

--enable-threads=posix: This option enables support for POSIX threads via the winpthreads library.

--disable-multilib: This option ensures that files are created for the specific architecture of your computer.

--enable-languages=c,c++: This command builds support for C and C++. Refer to https://www.linuxfromscratch.org/blfs/view/svn/general/gcc.html to find what other languages are supported.

ulimit -s 32768: This command prevents several tests from running out of stack space.

make -k check: This command runs the test suite without stopping if any errors are encountered.

../contrib/test_summary: This command will produce a summary of the test suite results. You can append | grep -A7 Summ to the command to produce an even more condensed version of the summary. You may also wish to redirect the output to a file for review and comparison later on.

Contents

There are no binaries specific to this package besides the format the compilers are targetting. For in-depth descriptions, read https://www.linuxfromscratch.org/lfs/view/stable/chapter08/gcc.html#contents-gcc