📡 MMDVMHost & DMRGateway
Windows Native Build Guide

✔️ MSYS2 / UCRT64 environment | 🪟 Run outside MSYS console (PowerShell / CMD)
⚙️ This guide compiles MMDVMHost and DMRGateway from source on Windows using the UCRT64 environment of MSYS2.
The resulting executables become standalone after copying required runtime DLLs – they work in PowerShell, Explorer double‑click, or on other Windows machines.

📦 1. Install MSYS2 & required packages

Download and install MSYS2 (64‑bit). After installation, launch UCRT64 shell from the Start menu (e.g., MSYS2 UCRT64). Then update and install toolchain + libraries:

# Update package databases and core system
pacman -Syu
# if shell closes, reopen UCRT64 and run:
pacman -Su

# Install compilers, make, git, and required libraries
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain git
pacman -S mingw-w64-ucrt-x86_64-libmosquitto
pacman -S mingw-w64-ucrt-x86_64-nlohmann-json
pacman -S mingw-w64-ucrt-x86_64-openssl
# optional but recommended for serial/UART support
pacman -S mingw-w64-ucrt-x86_64-libserialport
⚠️ Always use the UCRT64 shell (not MSYS2 or MINGW64). The path should show /ucrt64/bin/.... This produces pure Windows binaries without msys‑2.0.dll dependencies.

📁 2. Clone repositories

cd /d/workspace   # or any preferred folder
git clone https://github.com/g4klx/MMDVMHost.git
git clone https://github.com/g4klx/DMRGateway.git

🛠️ 3. Fix Makefiles (Windows socket & missing libs)

Both projects originally target Linux. Two edits are mandatory on Windows:

You can apply the changes manually or with sed. Below are the exact commands for each project.

🔧 Patch MMDVMHost Makefile

cd /d/workspace/MMDVMHost

# Remove -lutil and add required Winsock libraries
sed -i 's/-lutil //' Makefile
sed -i 's/LIBS    = -lpthread -lmosquitto/LIBS    = -lpthread -lmosquitto -lws2_32 -liphlpapi/' Makefile

# (Optional) remove -MD flag to avoid clang++ warnings – but not mandatory
# sed -i 's/-MD //' Makefile

🔧 Patch DMRGateway Makefile

cd /d/workspace/DMRGateway

sed -i 's/-lutil //' Makefile
sed -i 's/LIBS    = -lpthread -lmosquitto/LIBS    = -lpthread -lmosquitto -lws2_32 -liphlpapi/' Makefile
💡 If your LIBS line originally contained extra flags like -lssl -lcrypto, keep them. Only replace the core part. The sed above works for the standard MMDVMHost/DMRGateway Makefiles.

🏗️ 4. Compile both projects

# Build MMDVMHost
cd /d/workspace/MMDVMHost
make clean
make -j$(nproc)

# Build DMRGateway
cd /d/workspace/DMRGateway
make clean
make -j$(nproc)

After a successful build you will see MMDVMHost.exe and DMRGateway.exe in their respective folders.

📎 5. Gather runtime DLLs (standalone execution)

The executables depend on a few DLLs from /ucrt64/bin/. To run them outside the MSYS2 environment (PowerShell, CMD, or another PC), copy these DLLs into the same directory as the .exe.

Identify required DLLs

cd /d/workspace/MMDVMHost
ldd MMDVMHost.exe | grep -E "ucrt64|mingw"

Typical list (copy all of them):

DLLPurpose
libgcc_s_seh-1.dllGCC runtime (exception handling)
libstdc++-6.dllC++ standard library
libwinpthread-1.dllPOSIX threads for Windows
libmosquitto.dllMQTT client (if used)
libssl-3-x64.dll / libcrypto-3-x64.dllOpenSSL (for secure connections)

Copy DLLs automatically (for each project)

# For MMDVMHost
cd /d/workspace/MMDVMHost
cp /ucrt64/bin/libgcc_s_seh-1.dll .
cp /ucrt64/bin/libstdc++-6.dll .
cp /ucrt64/bin/libwinpthread-1.dll .
cp /ucrt64/bin/libmosquitto.dll .
cp /ucrt64/bin/libssl-3-x64.dll .
cp /ucrt64/bin/libcrypto-3-x64.dll .

# Repeat for DMRGateway
cd /d/workspace/DMRGateway
cp /ucrt64/bin/libgcc_s_seh-1.dll .
cp /ucrt64/bin/libstdc++-6.dll .
cp /ucrt64/bin/libwinpthread-1.dll .
cp /ucrt64/bin/libmosquitto.dll .
cp /ucrt64/bin/libssl-3-x64.dll .
cp /ucrt64/bin/libcrypto-3-x64.dll .
🧩 If your build uses extra libraries (like libsamplerate), add them too. Check ldd yourprogram.exe for any missing found => not found.

🚀 6. Run in PowerShell / Windows Explorer

Now you can close the MSYS2 console and use the native Windows environment.

You can also create a simple run_mmdvm.bat script:

@echo off
cd /d D:\workspace\MMDVMHost
MMDVMHost.exe MMDVMHost.ini
pause

🔁 7. Optional: static linking (one-file deployment)

If you prefer a single .exe without external DLLs, add -static to LDFLAGS in the Makefile:

LDFLAGS = -g -static -L/usr/local/lib

Then make clean && make. The resulting binary will be larger (5–15 MB) but fully standalone.

🧪 Troubleshooting quick reference

ErrorSolution
undefined reference to `__imp_sendto`
__imp_WSAStartup
Add -lws2_32 -liphlpapi to LIBS in Makefile.
cannot find -lutilRemove -lutil from LIBS (not present on Windows).
nlohmann/json.hpp: No such fileInstall mingw-w64-ucrt-x86_64-nlohmann-json
mosquitto.h: No such fileInstall mingw-w64-ucrt-x86_64-libmosquitto
libgcc_s_seh-1.dll is missing when running on another PCCopy the DLLs listed in step 5 to the same folder as exe.

✅ Final verification

After following the steps, both applications will run smoothly on any Windows 10/11 system (64‑bit). You can even copy the whole folder (exe + DLLs + config) to another machine without installing MSYS2.

🎯 Summary of critical changes: patch Makefiles (remove -lutil, add -lws2_32 -liphlpapi), compile, copy DLLs. The same approach works for other G4KLX projects like MMDVM_Framework based software.