# C++ Win32 Development Setup — RAMKeeper Target: build a ~800 KB static Win32 executable with no runtime dependencies, targeting Windows 10+. --- ## Option A: MSVC (Recommended) MSVC produces the smallest static binaries for Win32 and has first-class support for all Windows SDK headers. ### Step 1: Install Visual Studio Build Tools Download **Build Tools for Visual Studio 2022** (not the full IDE — saves ~15 GB): https://aka.ms/vs/17/release/vs_BuildTools.exe Run installer → select **"Desktop development with C++"** workload → install. This gives you: - `cl.exe` — MSVC compiler - `link.exe` — linker - Windows SDK (kernel32, ntdll, shell32, psapi, user32 headers + libs) - MSBuild **Verify:** ```powershell # Open "Developer Command Prompt for VS 2022" (Start menu) then: cl # Expected: Microsoft (R) C/C++ Optimizing Compiler Version 19.x ``` ### Step 2: Install CMake Download from https://cmake.org/download/ → Windows x64 Installer. Check "Add CMake to system PATH" during install. **Verify:** ```powershell cmake --version # Expected: cmake version 3.x.x ``` ### Step 3: Install Ninja (optional but faster builds) ```powershell winget install Ninja-build.Ninja ``` **Verify:** ```powershell ninja --version ``` --- ## Option B: MinGW-w64 via MSYS2 (Alternative, open source) Use this if you want GCC instead of MSVC. Binary size is slightly larger (~1.2 MB with static linking). ### Step 1: Install MSYS2 Download from https://www.msys2.org/ → run installer → install to `C:\msys64`. ### Step 2: Install MinGW-w64 toolchain Open **MSYS2 UCRT64** terminal: ```bash pacman -Syu # update package DB pacman -S mingw-w64-ucrt-x86_64-gcc \ mingw-w64-ucrt-x86_64-cmake \ mingw-w64-ucrt-x86_64-ninja ``` Add to system PATH: `C:\msys64\ucrt64\bin` **Verify:** ```powershell g++ --version # Expected: g++ (Rev...) 13.x.x MinGW-W64 ``` --- ## Project Build (CMake) ### Configure (MSVC) Open **Developer Command Prompt for VS 2022**: ```powershell cd d:\Projects\RAMCleanerApp cmake -B build -G "Ninja" -DCMAKE_BUILD_TYPE=Release ``` Or with Visual Studio generator (no Ninja needed): ```powershell cmake -B build -G "Visual Studio 17 2022" -A x64 ``` ### Configure (MinGW) ```powershell cmake -B build -G "Ninja" -DCMAKE_BUILD_TYPE=Release ` -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ ``` ### Build ```powershell cmake --build build --config Release ``` Output: `build\RAMKeeper.exe` ### Clean rebuild ```powershell cmake --build build --config Release --clean-first ``` --- ## Static Linking (Zero Runtime Dependencies) `CMakeLists.txt` already sets these flags. For reference: **MSVC static CRT:** ```cmake set_property(TARGET RAMKeeper PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded") ``` This links `libcmt.lib` instead of `msvcrt.dll` — no Visual C++ Redistributable needed. **MinGW static:** ```cmake target_link_options(RAMKeeper PRIVATE -static -static-libgcc -static-libstdc++) ``` --- ## Verify Binary Has No External Dependencies After building: ```powershell # MSVC: use dumpbin dumpbin /dependents build\RAMKeeper.exe # Expected output (only OS-guaranteed DLLs): # kernel32.dll # ntdll.dll # user32.dll # shell32.dll # psapi.dll # MinGW: use objdump objdump -p build\RAMKeeper.exe | grep "DLL Name" ``` If you see `VCRUNTIME140.dll`, `MSVCP140.dll`, or `libgcc_s_sjlj-1.dll` — static linking is not configured correctly. --- ## Required Windows SDK Components These are included automatically with the MSVC Build Tools install. Confirm presence: | Header | SDK location | Purpose | |---|---|---| | `windows.h` | `%VCToolsInstallDir%\..\..\Windows Kits\10\Include\*\um\` | Base types | | `psapi.h` | same | `EnumProcesses`, `EmptyWorkingSet` | | `winternl.h` | same | `NtSetSystemInformation` | | `shellapi.h` | same | `Shell_NotifyIcon` | --- ## IDE Setup (Optional) ### VS Code + clangd 1. Install extensions: **C/C++ Extension Pack**, **CMake Tools** 2. Open folder `d:\Projects\RAMCleanerApp` 3. CMake Tools auto-detects `CMakeLists.txt` → click "Configure" 4. IntelliSense works via `compile_commands.json` (generated by CMake with `-DCMAKE_EXPORT_COMPILE_COMMANDS=ON`) ### Visual Studio 2022 (full IDE) Open → `Open a local folder` → select project root → VS auto-detects `CMakeLists.txt`. --- ## Quick Sanity Test After setup, compile this minimal Win32 program to confirm everything works: ```cpp // test_win32.cpp #include #include int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { MEMORYSTATUSEX ms{}; ms.dwLength = sizeof(ms); GlobalMemoryStatusEx(&ms); ULONGLONG totalMB = ms.ullTotalPhys / (1024 * 1024); wchar_t buf[64]; wsprintfW(buf, L"Total RAM: %llu MB", totalMB); MessageBoxW(nullptr, buf, L"RAM Test", MB_OK); return 0; } ``` **MSVC (Developer Command Prompt):** ```powershell cl /W4 /O2 /MT /EHsc test_win32.cpp kernel32.lib psapi.lib user32.lib /Fe:test_win32.exe /link /SUBSYSTEM:WINDOWS .\test_win32.exe ``` **MinGW:** ```powershell g++ -O2 -static test_win32.cpp -lkernel32 -lpsapi -luser32 -mwindows -o test_win32.exe .\test_win32.exe ``` A message box showing your total RAM → setup is correct. --- ## Summary | Tool | Version | Required | |---|---|---| | MSVC / g++ | 2022 / 13+ | Yes | | CMake | 3.20+ | Yes | | Ninja | any | Optional (faster) | | Windows SDK | 10.0.19041+ | Yes (bundled with MSVC) | | winget | any | Optional (package install) |