Score:0

How to install mingw-w64-x86_64-gtk3 in Ubuntu 22.04?

cn flag

I am using MingW32 and am trying to install the package mingw-w64-x86_64-gtk3, however, that's not available via the apt install and it looks like you could only install it via pacman. Could someone show me the way to make it work (possibly without using MSYS2, as I pretty much got everything working except I'm missing the GTK3 part).

Namely, I need this package but it looks like you could only get it off MSYS2 using pacman: https://packages.msys2.org/package/mingw-w64-x86_64-gtk3

Environment/Setup:

  • Windows 11
  • Ubuntu 22.04 (WSL2)
    • apt install mingw-w64

I am able to compile all my CLI executables inside the Ubuntu 22.04 with MingW32 and running it fine in Windows.. I also have 2 small GUI applications that I want to get them to work too and they uses GTK3. I am able to compile them too but only in Windows using MSYS2, but I really want to just compile/build everything off Ubuntu environment to keep everything simple.

guiverc avatar
cn flag
https://packages.ubuntu.com/jammy/mingw-w64 is found in Ubuntu repositories, why not use it?
codenamezero avatar
cn flag
Because there is no gtk3? I am already using `mingw-w64-x86-64`
HolyBlackCat avatar
cn flag
Are you on Windows (+WSL) or on actual Linux? Where did you get your existing mingw32?
codenamezero avatar
cn flag
I am on Windows running Ubuntu 22.04 (WSL2), I've updated my original post to describe my setup. I was going to try to install `pacman` in Ubuntu and then just maybe try to install `mingw-w64-x86_64-gtk3` but I read that it is not recommended to use `pacman`.
HolyBlackCat avatar
cn flag
Please use @username when replying, otherwise I don't get notifications.
HolyBlackCat avatar
cn flag
Forget about WSL, use MSYS2 directly on Windows. Cross-compilation (which is what you're attempting now, aka producing apps for one OS while using another) is more complex that just developing on the correct OS in the first place. [Installation guide](https://stackoverflow.com/q/30069830/2752075).
codenamezero avatar
cn flag
@HolyBlackCat Thanks for your input, but I already know and could build directly in Windows. The whole point is to avoid having to separate building environments. MSYS2 is basically just running it in another simulated environment using mingw, which is pretty much what I am using in Ubuntu. In fact, I could build the CLI exe just fine, I am only missing the GTK portion. If you need to build it directly on a different platform, it is not "cross-compilation" now is it?
HolyBlackCat avatar
cn flag
You end up with an extra build environment one way or another. I [made a tool](https://github.com/HolyBlackCat/quasi-msys2) to download MSYS2 packages on Linux, you can use it to install GTK. It may or may not be compatible with MinGW provided by Ubuntu, but the recommended compilation method doesn't rely on external MinGW. I can write a full answer if needed.
codenamezero avatar
cn flag
@HolyBlackCat that would be great. If I read your repo correctly, lets say I need `mingw-w64-x86_64-gtk3`, I would clone your repo, type in `make install mingw-w64-x86_64-gtk3` and the MSYS2 package would become magically usable like the rest of the mingw packages?
HolyBlackCat avatar
cn flag
The package will be installed to the current directory, which you then have to add to compiler search paths.
HolyBlackCat avatar
cn flag
Did my tool work correctly for you?
Score:1
cn flag

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
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.