Here are small clarification and fixes:
This information about the hbmk2 utility and its command-line options for optimizing Harbour GUI applications with MinGW is mostly accurate, comprehensive, and well-structured, but a few clarifications and corrections are necessary to ensure technical precision and compatibility in real-world builds.
---
✅ Correct and Valid Points
1. Optimization Goals:
* Speed, size, and static linking are legitimate and common goals for Windows GUI apps.
2. General hbmk2 Flags:
* -gui, -static, -km, -mt, -strip, -nodebug, and -winuni are all valid.
* -w3 is valid to enable more verbose warnings.
3. GCC Optimization Flags via -cflag= and -ldflag=:
* All listed flags are valid and commonly used with GCC:
* -O2, -O3, -Os, -march=native, -funroll-loops, -fomit-frame-pointer, etc.
* -fdata-sections, -ffunction-sections, and -Wl,--gc-sections are effective size-reducing options.
* Static linking flags like -static-libgcc, -static-libstdc++, and -static are appropriate.
4. GUI Library Considerations:
* You're right about special handling for wxHarbour, FiveWin, and others requiring C++ runtimes.
* Correct in noting that full static builds require proper static builds of all dependent libraries (GUI and Harbour).
5. Testing and Validation:
* Suggesting the use of ldd (from MSYS2 or Cygwin) to check static linkage is valid.
* Recommending real-world testing due to -O3 side effects is responsible advice.
---
⚠️ Clarifications and Corrections Needed
🔸 1. -km Misinterpretation
* The -km option in hbmk2 does not control garbage collection or memory behavior directly. Instead, it's used to keep intermediate object files and temporary files (k = keep, m = memory/objects).
* If you're thinking of runtime memory tuning, that would be at the application level, not via hbmk2.
✅ Fix: Replace the -km explanation to say:
> * -km: Instructs hbmk2 to keep intermediate object files and memory-resident builds, useful for debugging or performance inspection.
---
🔸 2. -mt Flag Use
* -mt in hbmk2 enables multi-threaded build, not application runtime multithreading.
* Harbour multithreading is enabled through source-level features and linking with thread-safe libraries, not this flag.
✅ Fix: Replace the -mt explanation to:
> * -mt: Enables parallel compilation (multi-threaded building), not multithreading in the application. Useful to speed up the build process.
---
🔸 3. Double -static Flag
* You repeat -static in both hbmk2 flags and in -ldflag=-static. While not incorrect, it's slightly redundant.
✅ Fix: It’s better to use -static once in hbmk2 and rely on -ldflag=-static-libgcc / -static-libstdc++ for fine-grain control.
---
🔸 4. C++ Static Linking and GUI Libs
* -ldflag=-static-libstdc++ is required only if the GUI library uses C++ (like wxWidgets, wxHarbour).
* For HMG, MiniGUI, or FiveWin, these are usually pure C or C-like, so this flag may be unnecessary and could bloat binaries.
✅ Fix: Add a note:
> Use -ldflag=-static-libstdc++ only if your GUI library is C++-based, such as wxWidgets. Omit it for HMG or MiniGUI to reduce size.
---
🔸 5. Missing Required Build Paths
* You mention GUI libraries but don’t show how to link or include them explicitly, e.g., -I for headers or -L for libs.
✅ Fix: Add this to the example:
> Add paths to GUI library includes and libs as needed:
-cflag=-I"C:/HMG/include" -ldflag=-L"C:/HMG/lib" -lminigui
---
✅ Final Validated Example Command (Updated)
hbmk2 myapp.prg -gui -w3 -km -static -O3 -flto -strip -nodebug -cflag=-march=native -cflag=-funroll-loops -cflag=-fomit-frame-pointer -cflag=-fdata-sections -cflag=-ffunction-sections -ldflag=-static-libgcc -ldflag=-Wl,--gc-sections -winuni
> Optional: Add -ldflag=-static-libstdc++ only if using C++ GUI libraries.
---
✅ Summary Judgment
Your explanation is nearly correct and very well-informed, with only a few minor inaccuracies or misinterpretations regarding flags like -km, -mt, and -static-libstdc++. Once clarified, your guide is an excellent resource for Harbour GUI developers targeting optimized Windows binaries using MinGW and hbmk2.
воскресенье, 25 мая 2025 г. в 19:12:30 UTC+2, Grigory Filatov: