Skip to content

Compiling Binaries

Linux Target

Basic C

gcc source.c -o myprog

Windows Target

sudo apt install mingw-w64
Basic C Compilation 32-bit β€œHello World” (console)
i686-w64-mingw32-gcc -O2 -Wall hello.c -o hello32.exe
64-bit β€œHello World” (console)
x86_64-w64-mingw32-gcc -O2 -Wall hello.c -o hello64.exe
Basic C++ Compilation 32-bit C++ (console)
i686-w64-mingw32-g++ -O2 -std=c++17 -Wall hello.cpp -o hello32.exe
64-bit C++ (console)
x86_64-w64-mingw32-g++ -O2 -std=c++17 -Wall hello.cpp -o hello64.exe
Setting Windows Version Macros To target a minimum Windows version, define _WIN32_WINNT and WINVER:
# Example: target Windows 7 (0x0601)
x86_64-w64-mingw32-gcc -D_WIN32_WINNT=0x0601 -DWINVER=0x0601 hello.c -o hello.exe
Common _WIN32_WINNT values:

  • 0x0501 β†’ Windows XP
  • 0x0600 β†’ Windows Vista
  • 0x0601 β†’ Windows 7
  • 0x0602 β†’ Windows 8
  • 0x0A00 β†’ Windows 10

.NET Excutables

sudo apt install -y mono-devel mono-mkbundle
sudo apt install -y gcc-mingw-w64-x86-64
sudo apt install -y gcc-mingw-w64-i6
Compile to a portable .NET EXE (IL-only) using Mono’s C# compiler (mcs):
mcs -out:Hello.exe Hello.cs
Basic 64-bit Windows EXE
mkbundle \
  --cross mono-w64 --simple \
  --static \
  --deps \
  -o Hello_native.exe \
  Hello.exe
For 32-bit Windows (Win32)
mkbundle \
  --cross mono-w64-i686 \
  --simple \
  --static \
  --deps \
  -o Hello_native32.exe \
  Hello.exe

.csproj

wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt update
sudo apt install -y dotnet-sdk-7.0
dotnet --info
Ensure there’s a YourProject.csproj in that directory (or a parent directory). Restore dependencies
dotnet restore
Build
dotnet build -c Release

  • By default, the output goes into bin/Release/<TargetFramework>/
  • If you want to target a specific runtime (e.g. Windows), use: Target runtime
    dotnet publish -c Release -r win-x64 --self-contained false