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
MinGW-w64-GCC provides GCC compilers for MinGW-w64, allowing users and applications to compile code targetting Windows.
Development versions of GLFS may not build or run some packages properly if LFS or dependencies have been updated since the most recent stable versions of the books.
Download (HTTP): https://ftp.gnu.org/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.xz
Binary MinGW-w64, MinGW-w64-binutils-2.42, MinGW-w64-CRT-11.0.1, MinGW-w64-headers-11.0.1, and MinGW-w64-winpthreads-11.0.1,
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.
Ensure that on x86_64 that the library directory is /lib:
case $(uname -m) in x86_64) sed -e '/m64=/s/lib64/lib/' \ -i.orig gcc/config/i386/t-linux64 ;; esac
The instructions below are intentionally performing a “bootstrap”
process. Bootstrapping is needed for robustness and is highly
recommended when upgrading the compilers version. To disable
bootstrap anyway, add --disable-bootstrap
to the
./configure options
below.
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 \ --libexecdir=/usr/lib \ --target=x86_64-w64-mingw32 \ --enable-shared \ --enable-static \ --disable-multilib \ --enable-threads=posix \ --enable-fully-dynamic-string \ --enable-libstdcxx-time=yes \ --enable-libstdcxx-filesystem-ts=yes \ --with-system-zlib \ --enable-default-pie \ --enable-default-ssp \ --enable-languages=c,c++ make -j1
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 -sv x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-cc && mv -v /usr/x86_64-w64-mingw32/lib/*.dll /usr/x86_64-w64-mingw32/bin
The instructions below are intentionally performing a “bootstrap”
process. Bootstrapping is needed for robustness and is highly
recommended when upgrading the compilers version. To disable
bootstrap anyway, add --disable-bootstrap
to the
./configure options
below.
Install i686 MinGW-w64-GCC by running the following commands:
mkdir build-i686-mingw-w64 && cd build-i686-mingw-w64 && ../configure \ --prefix=/usr \ --libexecdir=/usr/lib \ --target=i686-w64-mingw32 \ --enable-shared \ --enable-static \ --disable-multilib \ --enable-threads=posix \ --enable-fully-dynamic-string \ --enable-libstdcxx-time=yes \ --enable-libstdcxx-filesystem-ts=yes \ --with-system-zlib \ --enable-default-pie \ --enable-default-ssp \ --enable-languages=c,c++ make -j1
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 -sv i686-w64-mingw32-gcc /usr/bin/i686-w64-mingw32-cc && mv -v /usr/i686-w64-mingw32/lib/*.dll /usr/i686-w64-mingw32/bin
Now that MinGW-w64-GCC and friends have been installed, it is time to clean up and test the MinGW-w64 installation to make sure everything is working as expected.
Remove the binary installation that was installed earlier as the
root
user:
rm -rf /opt/mingw-w64*
Now as the regular user, restore the PATH
variable to what it was beforehand:
export PATH=$PATH_HOLD && unset PATH_HOLD
Now it's time to test the installation. 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 -v main.c main.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 -v main.c main.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.
mkdir build; cd build: The GCC documentation recommends building the package in a dedicated build directory.
--enable-shared
: This
option builds needed shared libraries.
--enable-static
: This
option builds needed static libraries.
--disable-multilib
: This
option ensures that files are created for the specific architecture
of your computer.
--enable-threads=posix
:
This option ensures the POSIX threads standard is built in.
--enable-fully-dynamic-string
: This
option enables a special version of basic_string avoiding the
optimization that allocates empty objects in static memory.
--enable-libstdcxx-time=yes
: This
option enables link-type checks for the availability of the
clock_gettime clocks.
--enable-libstdcxx-filesystem-ts=yes
:
This option builds libstdc++fs.a
as
well as the usual libstdc++ and libsupc++ libraries.
--with-system-zlib
: Uses
the system zlib instead of the
bundled one. zlib is used for
compressing and decompressing GCC's intermediate language in LTO (Link Time
Optimization) object files.
--enable-default-pie
: Makes
the -fpie
option the default when
compiling programs. Together with the ASLR feature enabled in the kernel, this
defeats some kind of attacks based on known memory layouts.
--enable-default-ssp
: Makes
the -fstack-protector-strong
option the
default when compiling programs. SSP is a technique preventing alteration of
the program flow by corrupting the parameter stack.
--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.
make -j1: Using more than one thread can lead to a race condition and cause the compilation to fail, so this option prevents that by using only one thread.
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.
mv -v /usr/*/lib/*.dll /usr/*/bin: This command moves dll files to the proper directory.
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