I've made Quasi-MSYS2, which helps download MSYS2 packages on Linux.

sudo apt install make wget tar zstd gpg

git clone https://github.com/HolyBlackCat/quasi-msys2
cd quasi-msys2/
make install _gtk4   # equivalent to `make install mingw-w64-x86_64-gtk4`

This downloads GTK4 to the current directory (./root/mingw64/) for you to use.

But there's a problem: MinGW comes in different flavors, and the flavors provided by MSYS2 may or may not be compatible with the flavor provided by Ubuntu.

The recommended build method doesn't depend on external MinGW. Instead I suggest using Clang, which can work with any MinGW flavor, if provided the right libraries (which we download from MSYS2).

sudo apt install wine   # Optional.

# Install latest Clang
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh
rm llvm.sh

# Install more packages
make install _gcc _gdb    # We won't be using GCC, but we need libraries that come with it.

# Opens a new shell with the right environment variables configured.
env/shell.sh

Then, testing on Hello World from here:

# Notice `pkg-config` picking up the correct libraries.
win-clang++ hello_world.cpp `pkg-config --cflags --libs gtk4`
# This opens the app in Wine:
./a.exe
Answer from HolyBlackCat on askubuntu.com
Top answer
1 of 3
34

Look more closely at what is actually available:

edd@max:~$ apt-cache search mingw-
libassuan-mingw-w64-dev - IPC library for the GnuPG components -- Windows port
libgcrypt-mingw-w64-dev - LGPL Crypto library - Windows development
libgpg-error-mingw-w64-dev - library of error values and messages in GnuPG (Windows development)
libksba-mingw-w64-dev - X.509 and CMS support library (Windows development)
libnpth-mingw-w64-dev - replacement for GNU Pth using system threads (Windows dev)
binutils-mingw-w64 - Cross-binutils for Win32 and Win64 using MinGW-w64
binutils-mingw-w64-i686 - Cross-binutils for Win32 (x86) using MinGW-w64
binutils-mingw-w64-x86-64 - Cross-binutils for Win64 (x64) using MinGW-w64
g++-mingw-w64 - GNU C++ compiler for MinGW-w64
g++-mingw-w64-i686 - GNU C++ compiler for MinGW-w64 targeting Win32
g++-mingw-w64-x86-64 - GNU C++ compiler for MinGW-w64 targeting Win64
gcc-mingw-w64 - GNU C compiler for MinGW-w64
gcc-mingw-w64-base - GNU Compiler Collection for MinGW-w64 (base package)
gcc-mingw-w64-i686 - GNU C compiler for MinGW-w64 targeting Win32
gcc-mingw-w64-x86-64 - GNU C compiler for MinGW-w64 targeting Win64
gdb-mingw-w64 - Cross-debugger for Win32 and Win64 using MinGW-w64
gdb-mingw-w64-target - Cross-debugger server for Win32 and Win64 using MinGW-w64
gfortran-mingw-w64 - GNU Fortran compiler for MinGW-w64
gfortran-mingw-w64-i686 - GNU Fortran compiler for MinGW-w64 targeting Win32
gfortran-mingw-w64-x86-64 - GNU Fortran compiler for MinGW-w64 targeting Win64
gnat-mingw-w64 - GNU Ada compiler for MinGW-w64
gnat-mingw-w64-base - GNU Ada compiler for MinGW-w64 (base package)
gnat-mingw-w64-i686 - GNU Ada compiler for MinGW-w64 targeting Win32
gnat-mingw-w64-x86-64 - GNU Ada compiler for MinGW-w64 targeting Win64
gobjc++-mingw-w64 - GNU Objective-C++ compiler for MinGW-w64
gobjc++-mingw-w64-i686 - GNU Objective-C++ compiler for MinGW-w64 targeting Win32
gobjc++-mingw-w64-x86-64 - GNU Objective-C++ compiler for MinGW-w64 targeting Win64
gobjc-mingw-w64 - GNU Objective-C compiler for MinGW-w64
gobjc-mingw-w64-i686 - GNU Objective-C compiler for MinGW-w64 targeting Win32
gobjc-mingw-w64-x86-64 - GNU Objective-C compiler for MinGW-w64 targeting Win64
libz-mingw-w64 - compression library - Windows runtime
libz-mingw-w64-dev - compression library - Windows development files
mingw-ocaml - ocaml-mingw-w64 transitional dummy package
mingw-w64 - Development environment targeting 32- and 64-bit Windows
mingw-w64-common - Common files for Mingw-w64
mingw-w64-i686-dev - Development files for MinGW-w64 targeting Win32
mingw-w64-tools - Development tools for 32- and 64-bit Windows
mingw-w64-x86-64-dev - Development files for MinGW-w64 targeting Win64
ocaml-mingw-w64 - OCaml cross-compiler based on mingw -- Meta-package
ocaml-mingw-w64-i686 - OCaml cross-compiler based on mingw -- 32 bit compiler
ocaml-mingw-w64-x86-64 - OCaml cross-compiler based on mingw -- 64 bit compiler
edd@max:~$

So sudo apt-get install gcc-mingw-w64 is probably what you want, and you should get a 32-bit executable built by setting the appropriate compiler option, likely -m32.

2 of 3
6

I tried sudo apt-get install gcc-mingw-w64.

And then I compile the code with the command :

i686-w64-mingw32-gcc-win32 input_code.c -o output.exe
🌐
Ubuntu
launchpad.net › ubuntu › +source › mingw-w64
mingw-w64 package : Ubuntu
mingw-w64: Development environment targeting 32- and 64-bit Windows mingw-w64-common: Common files for Mingw-w64 mingw-w64-i686-dev: Development files for MinGW-w64 targeting Win32 mingw-w64-tools: Development tools for 32- and 64-bit Windows mingw-w64-
🌐
mingw-w64
mingw-w64.org › downloads
Pre-built Toolchains - mingw-w64
mingw-w64 packages on Ubuntu · w64devkit is a portable C and C++ development kit for x64 (and x86) Windows. Included tools: mingw-w64 GCC : compilers, linker, assembler · GDB : debugger · GNU Make : standard build tool · busybox-w32 : standard unix utilities, including sh ·
🌐
YouTube
youtube.com › watch
How to install MinGW-W64 Compiler on Ubuntu 22.04 LTS - YouTube
In this video I will show how to install MinGW-W64 Compiler on Ubuntu 22.04 LTSThank You For Visiting My Channel.****** Subscribe & Support ******
Published   April 23, 2022
🌐
YouTube
youtube.com › watch
How To Install MinGW on Ubuntu 22.04 - YouTube
install mingw-w64 on ubuntuHow To Install mingw-w64 on Ubuntu 22.04How To Install "mingw-w64" Package on UbuntuHow to install mingw32 on UbuntuInstall mingw-...
Published   June 30, 2022
🌐
mingw-w64
mingw-w64.org › getting-started › debian
Debian / Ubuntu - mingw-w64
A complete runtime environment for GCC & LLVM for 32-bit (x86), 64-bit (x64), and ARM64 Windows
🌐
Ubuntu
launchpad.net › ubuntu › +source › gcc-mingw-w64
gcc-mingw-w64 package : Ubuntu
g++-mingw-w64: GNU C++ compiler for MinGW-w64 g++-mingw-w64-i686: GNU C++ compiler for MinGW-w64 targeting Win32 g++-mingw-
🌐
SpeakGoodChinese
fon.hum.uva.nl › rob › CompilingPraatOnXP › recipe.html
sudo apt-get install mingw-w64
The instructions are tested for Lubuntu Linux (version 14.04 LTS), therefore they should work for Debian, Ubuntu (and relatives) and Mint as well. It is assumed that the reader is familiar with Linux. We wil use Praat 5.4.15 and and compile the source code by using mingw-w64 version 3.2.0-2 ...
Find elsewhere
🌐
Ubuntu
launchpad.net › ubuntu › bionic › +package › mingw-w64
mingw-w64 : Bionic (18.04) : Ubuntu
MinGW-w64 provides a development and runtime environment for 32- and 64-bit (x86 and x64) Windows applications using the Windows API and the GNU Compiler Collection (gcc). . This metapackage provides the MinGW-w64 development environment, including ...
🌐
Ubuntu
packages.ubuntu.com › focal › mingw-w64
Ubuntu – Error
two or more packages specified (mingw-w64 focal) Content Copyright © 2025 Canonical Ltd.; See license terms. Ubuntu is a trademark of Canonical Ltd. Learn more about this site.
🌐
Installati.one
installati.one › home › how to install mingw-w64 on ubuntu 20.04
How To Install mingw-w64 on Ubuntu 20.04 | Installati.one
June 13, 2023 - In this tutorial we learn how to install mingw-w64 on Ubuntu 20.04. mingw-w64 is Development environment targeting 32- and 64-bit Windows
🌐
CircleCI
discuss.circleci.com › build environment
How to install mingw-w64 packages into a machine or docker image? - Build Environment - CircleCI Discuss
February 23, 2023 - Hi all! Converting from Travis, one of our builds requires the use of the MinGW-w64 dev tools (installed under Linux) to do its job. I tried various ways to install mingw-related packages into the (ubuntu) images, but …
🌐
Ubuntu
launchpad.net › ubuntu › focal › +package › mingw-w64-tools
mingw-w64-tools : Focal (20.04) : Ubuntu
MinGW-w64 provides a development and runtime environment for 32- and 64-bit (x86 and x64) Windows applications using the Windows API and the GNU Compiler Collection (gcc). . This package contains: * gendef, which extracts DLL exports from Windows ...