MinGW-w64-GCC-15.2.0

#### Gaming Linux® From Scratch - Version 13.0

### Chapter 20. The MinGW-w64 Toolchain

- Prev

  MinGW-w64-13.0.0

- Next

  Miscellaneous

- Up
- Home

# MinGW-w64-GCC-15.2.0

## Introduction to MinGW-w64-GCC

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

### Note

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

- Download: https://ftpmirror.gnu.org/gnu/gcc/gcc-15.2.0/gcc-15.2.0.tar.xz

### MinGW-w64-GCC Dependencies

Required
MinGW-w64-13.0.0

## Installation of MinGW-w64-GCC

### Note

Since you are targeting a triplet different from the host, running make install is generally safe, unlike a standard installation of a compiler which if it has been built wrong can brick the toolchain entirely.

If you are building from a new GCC source tree, be sure to apply the patch from Static MinGW-w64-GCC-15.2.0.

### 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

Now, as the `root` user:

    make install &&
    cd ..        &&

    ln -sfv x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-cc &&
    strip /usr/libexec/gcc/x86_64-w64-mingw32/15.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

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/15.2.0/{cc1*,collect2,lto*}

## Testing the Toolchain

Now that the MinGW-w64 cross toolchain has been fully installed, it is time to test the 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}

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

### Note

Run ../configure --help for a full list of options.

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/13.0-systemd/general/gcc.html to find what other languages are supported.

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 targeting, and thus are prefixed with the architecture triplet, such as x86_64-w64-mingw32-gcc. For in-depth descriptions, read https://www.linuxfromscratch.org/lfs/view/13.0-systemd/chapter08/gcc.html#contents-gcc.

- Prev

  MinGW-w64-13.0.0

- Next

  Miscellaneous

- Up
- Home