I know that if I want to compile a 32 bit .exe for windows on Linux I can just install and use the mingw32 package (e.g. apt-get install mingw32) on linux. What if I want to compile a windows .exe that is 64 bit? Is there tools or a method to do this?
It looks like my answer lies with the Mingw-w64 project which is available for host OSes Linux, Darwin & Windows
I know this question is very old and already has an accepted answer but I will post this answer the way I do it now. It is pretty simple and straightforward and I hope it helps anyone landing here:
To cross-compile windows applications from a Linux machine you just need to install mingw-w64
C and C++ compiler. On debian based system you just do this:
sudo apt install -y gcc-mingw-w64 g++-mingw-w64
That will install the gcc
(the c compiler) and g++
(the c++ compiler) for both 64 and 32 bit cross-compilation
After that, if you need a 64-bit application just do:
x86_64-w64-mingw32-g++ hello.c -o hello.exe
And if you need a 32-bit application just do:
i686-w64-mingw32-g++ hello.c -o hello.exe
Simple as that!
It's also possible to install MinGW from MSYS2. The main advantages are:
- Usually up-to-date MinGW, regardless of what your Linux distribution ships.
- A lot of prebuilt libraries.
Several MinGW flavors are provided: x32 and x64, with different C runtimes, etc.
You can't install MSYS2 on Linux directly, but it's possible with Quasi-MSYS2.
Install Clang (and LLD):
On Ubuntu:
wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh sudo ./llvm.sh rm llvm.sh
Clang can cross-compile to Windows using MSYS2 libraries. Alternatively, you can run MSYS2 MinGW in Wine, but it's slower.
Install dependencies:
sudo apt install make wget tar zstd gpg wine
Wine is optional.
Install Quasi-MSYS2 and any desired MSYS2 packages:
git clone https://github.com/HolyBlackCat/quasi-msys2 cd quasi-msys2/ # Optionally, choose MSYS2 flavor, see full list at: https://www.msys2.org/docs/environments/ # echo MINGW64 >msystem.txt make install _gcc _gdb
Then:
env/shell.sh
opens a shell with the correct environment variables set up.win-clang++ hello.cpp
invokes Clang with flags for cross-compilation../a.exe
runs the resulting app in Wine, if it's installed.
Full disclosure: I'm the developer of quasi-msys2.
© 2022 - 2024 — McMap. All rights reserved.
apt-get install mingw32
inorder to produce exe? Can you also please try to answer my questions #2733902 and #2731711 and #2710089 – Dnieper