How to use the xPack MinGW-w64 GCC
This page is intended for those who plan to use the xPack MinGW-w64 GCC binaries in their workflows.
Miscellaneous
-static-libgcc -static-libstdc++
To avoid issues with DLLs, specific when using toolchains installed in custom locations, it is highly recommended to use only the static versions of the GCC libraries.
For C programs, append -static-libgcc
to the linker line.
For C++ programs, since the toolchain is configured to use POSIX threads,
instead of -static-libstdc++
, use the more explicit variant
-Wl,-Bstatic,-lstdc++,-lpthread,-Bdynamic
when invoking the linker.
libwinpthread-1.dll
Due to the specifics of the MinGW-w64 build, the threading library is
not very well integrated into the build, and invoking the compiler
with -static-libgcc -static-libstdc++
does not apply to this DLL,
so the resulting binaries might still have a reference to it.
Compiler DLLs
For projects that create multiple executables, using static libraries is not space efficient, especially for C++, since the code is multiplied in all executables.
The solution is to copy the required DLLs to the folder where the
compiled .exe files will be installed (like /bin
).
$ ls -l $(dirname $(bin/x86_64-w64-mingw32-g++ -print-file-name=libstdc++-6.dll))/*.dll
-rwxr-xr-x 1 ilg staff 38326 Sep 1 09:43 /Users/ilg/Work/xpack-dev-tools-build/mingw-w64-gcc-14.1.0-1/darwin-x64/application/lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libatomic-1.dll
-rwxr-xr-x 1 ilg staff 821363 Sep 1 09:43 /Users/ilg/Work/xpack-dev-tools-build/mingw-w64-gcc-14.1.0-1/darwin-x64/application/lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libgcc_s_seh-1.dll
-rwxr-xr-x 1 ilg staff 3159825 Sep 1 09:43 /Users/ilg/Work/xpack-dev-tools-build/mingw-w64-gcc-14.1.0-1/darwin-x64/application/lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libgfortran-5.dll
-rwxr-xr-x 1 ilg staff 282552 Sep 1 09:43 /Users/ilg/Work/xpack-dev-tools-build/mingw-w64-gcc-14.1.0-1/darwin-x64/application/lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libgomp-1.dll
-rwxr-xr-x 1 ilg staff 375291 Sep 1 09:43 /Users/ilg/Work/xpack-dev-tools-build/mingw-w64-gcc-14.1.0-1/darwin-x64/application/lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libquadmath-0.dll
-rwxr-xr-x 1 ilg staff 23251 Sep 1 09:43 /Users/ilg/Work/xpack-dev-tools-build/mingw-w64-gcc-14.1.0-1/darwin-x64/application/lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libssp-0.dll
-rwxr-xr-x 1 ilg staff 2222331 Sep 1 09:43 /Users/ilg/Work/xpack-dev-tools-build/mingw-w64-gcc-14.1.0-1/darwin-x64/application/lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libstdc++-6.dll
-rw-r--r-- 1 ilg staff 61838 Sep 1 09:40 /Users/ilg/Work/xpack-dev-tools-build/mingw-w64-gcc-14.1.0-1/darwin-x64/application/lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libwinpthread-1.dll
and
$ ls -l $(dirname $(bin/i686-w64-mingw32-g++ -print-file-name=libstdc++-6.dll))/*.dll
-rwxr-xr-x 1 ilg staff 37899 Sep 1 09:26 /Users/ilg/Work/xpack-dev-tools-build/mingw-w64-gcc-14.1.0-1/darwin-x64/application/lib/gcc/i686-w64-mingw32/14.1.0/../../../../i686-w64-mingw32/lib/../lib/libatomic-1.dll
-rwxr-xr-x 1 ilg staff 923876 Sep 1 09:26 /Users/ilg/Work/xpack-dev-tools-build/mingw-w64-gcc-14.1.0-1/darwin-x64/application/lib/gcc/i686-w64-mingw32/14.1.0/../../../../i686-w64-mingw32/lib/../lib/libgcc_s_dw2-1.dll
-rwxr-xr-x 1 ilg staff 2907410 Sep 1 09:26 /Users/ilg/Work/xpack-dev-tools-build/mingw-w64-gcc-14.1.0-1/darwin-x64/application/lib/gcc/i686-w64-mingw32/14.1.0/../../../../i686-w64-mingw32/lib/../lib/libgfortran-5.dll
-rwxr-xr-x 1 ilg staff 301246 Sep 1 09:26 /Users/ilg/Work/xpack-dev-tools-build/mingw-w64-gcc-14.1.0-1/darwin-x64/application/lib/gcc/i686-w64-mingw32/14.1.0/../../../../i686-w64-mingw32/lib/../lib/libgomp-1.dll
-rwxr-xr-x 1 ilg staff 557685 Sep 1 09:26 /Users/ilg/Work/xpack-dev-tools-build/mingw-w64-gcc-14.1.0-1/darwin-x64/application/lib/gcc/i686-w64-mingw32/14.1.0/../../../../i686-w64-mingw32/lib/../lib/libquadmath-0.dll
-rwxr-xr-x 1 ilg staff 23352 Sep 1 09:26 /Users/ilg/Work/xpack-dev-tools-build/mingw-w64-gcc-14.1.0-1/darwin-x64/application/lib/gcc/i686-w64-mingw32/14.1.0/../../../../i686-w64-mingw32/lib/../lib/libssp-0.dll
-rwxr-xr-x 1 ilg staff 2377884 Sep 1 09:26 /Users/ilg/Work/xpack-dev-tools-build/mingw-w64-gcc-14.1.0-1/darwin-x64/application/lib/gcc/i686-w64-mingw32/14.1.0/../../../../i686-w64-mingw32/lib/../lib/libstdc++-6.dll
-rw-r--r-- 1 ilg staff 72722 Sep 1 09:23 /Users/ilg/Work/xpack-dev-tools-build/mingw-w64-gcc-14.1.0-1/darwin-x64/application/lib/gcc/i686-w64-mingw32/14.1.0/../../../../i686-w64-mingw32/lib/../lib/libwinpthread-1.dll
Output folder hierarchy
The scripts build separate 32/64-bit versions of all tools, installed in
separate folders ("x86_64-w64-mingw32" "i686-w64-mingw32");
the binaries are installed in bin
and are prefixed.
The target specific dependencies are also installed in separate folders
below a folder specific to the build machine (like x86_64-apple-darwin21.6.0
).
├── README.md
├── bin
│ ├── i686-w64-mingw32-addr2line
│ ├── i686-w64-mingw32-ar
│ ├── i686-w64-mingw32-as
│ ├── i686-w64-mingw32-c++
│ ├── i686-w64-mingw32-c++filt
│ ├── i686-w64-mingw32-cpp
│ ├── i686-w64-mingw32-dlltool
│ ├── i686-w64-mingw32-dllwrap
│ ├── i686-w64-mingw32-elfedit
│ ├── i686-w64-mingw32-g++
│ ├── i686-w64-mingw32-gcc
│ ├── i686-w64-mingw32-gcc-12.2.0