Install Mingw-w64 on Ubuntu 24.04

Install Mingw-w64 on Ubuntu 24.04

Mingw-w64 is an open-source toolchain designed for creating Windows applications using the GCC. It can be used across different operating systems, including Linux, to produce native Windows binaries without requiring a Windows environment. This tutorial demonstrates how to install Mingw-w64 on Ubuntu 24.04.

Install Mingw-w64

Ensure that the package lists are up-to-date:

sudo apt update

Next, install the required Mingw-w64 compiler packages:

sudo apt install -y gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64

Verify that the compilers are available by checking their versions:

x86_64-w64-mingw32-gcc --version
x86_64-w64-mingw32-g++ --version

Testing Mingw-w64

Create a simple C source file:

nano main.c

Insert the following example code:

#include <stdio.h>

int main() {
    printf("Hello world\n");

    return 0;
}

Compile the program into a Windows executable:

x86_64-w64-mingw32-gcc main.c -o test.exe

If compilation succeeds, the output file test.exe can be executed on a Windows system.

Uninstall Mingw-w64

If Mingw-w64 is no longer needed, remove it along with any unnecessary dependencies by using the following command:

sudo apt purge --autoremove -y gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64

Leave a Comment

Cancel reply

Your email address will not be published.