![]() |
|
[Tutorial] Optimize your Visual Studio compile settings for Filesize (C++) - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Tutorial] Optimize your Visual Studio compile settings for Filesize (C++) (/showthread.php?tid=6292531) |
Optimize your Visual Studio compile settings for Filesize (C++) - WhiteTV - Feb 17, 2025 Generally in todays world you usually don't care anymore how big your compiled binary is. But in our domain, especially when it comes to Red Teaming and Malware development, you want the smallest possible filesize. Apart from optimized code, without external dependencies (looking at you OpenSSL with 5MB of size), you can optimize your Compile settings for reduced size. The following Visual Studio (2022) Settings are the ones I use. Compared to the default settings, these reduced the statically linked binary size in my case from 480kb to 300kb. Note that the following settings are for WinApi applications. If you want a console window, skip the SubSystem: Windows (/SUBSYSTEM:WINDOWS) setting Also some settings might not be available depending which VS or C++ versions you are using. Project Properties -> C/C++ -> Optimization:
Project Properties -> C/C++ -> Code Generation:
Project Properties -> C/C++ -> Preprocessor:
Project Properties -> Linker -> Debugging:
Project Properties -> Linker -> System:
Project Properties -> Linker -> Command Line: Add these additional options: Code /EMITPOGOPHASEINFO:NO /INCREMENTAL:NO /RELEASEProject Properties -> C/C++ -> Advanced:
Project Properties -> C/C++ -> General:
Project Properties -> Build Events -> Post-Build Event: Add command to strip debug symbols: Code strip "$(TargetPath)"Edit: To further analyze your binary, SizeBench from Windows can be used to exactly show you which libraries are taking up a lot of space in your compiled Binary. https://github.com/microsoft/SizeBench |