简体   繁体   中英

How do I find out where the size of the final executable comes from in C++?

Let's say that I have a C++ program, which when compiled, produces an executable binary many megabytes in size. How do I find out where this size came from? Is there a tool that can show that X% of the size came from file or class Y, etc?

Ideally, I'm looking for a tool similar to Disk Usage Analyzer that can break down what makes up an executable into some kind of pie chart or other graph. If not, at least having the information available would allow creating charts.

The final goal would be to identify parts of the program that I can exclude from the executable to shrink it down and optimize for size, starting from the largest pieces of unnecessary code.

You could take a look at Bloaty McBloatface , which claims to be designed to do exactly this:

Ever wondered what's making your binary big? Bloaty McBloatface will show you a size profile of the binary so you can understand what's taking up space inside.

Bloaty performs a deep analysis of the binary. Using custom ELF, DWARF, and Mach-O parsers, Bloaty aims to accurately attribute every byte of the binary to the symbol or compileunit that produced it. It will even disassemble the binary looking for references to anonymous data. For more information about the analysis performed by Bloaty, please see doc/how-bloaty-works.md.

Bloaty works on binaries, shared objects, object files, and static libraries (.a files). The following file formats are supported:

ELF
Mach-O
WebAssembly (experimental)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM