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.comLook 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.
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
You need to copy this libstdc++-6.dll from your mingw installation (should be in /usr/lib/gcc/x86-w64-mingw32/9.3-win32/) to the same directory as your exe file. I expect you will get a similar message about libgcc_s_sjlj-1.dll, which you also need to copy.
I tested this with 32-bit and on a windows VM, but I hope that that will not make a difference.
You are getting errors because Wine doesn't know where those libraries are available. You have two options:
- Place all required libraries in the same directory
- Statically link with required libraries
If you don't have licensing issues (e.g libstdc++ uses LGPL, to link with that library, you need to license your program under LGPL if you distribute it), you should statically link. For a hello world program, the compilation command will be like this:
x86_64-w64-mingw32-g++ hello.cpp -static-libstdc++ -static-libgcc -o hello
Another option is to place all libraries at the same directory. So just copy those files from /usr/lib/gcc/x86_64-w64-mingw32/9.3-win32/ or /usr/lib/gcc/x86-w64-mingw32/9.3-win32/ and your program should run well.