Size of a library and the executable

前端 未结 7 881
半阙折子戏
半阙折子戏 2021-02-14 12:14

I have a static library *.lib created using MSVC on windows. The size of library is say 70KB. Then I have an application which links this library. But now the size of the final

7条回答
  •  清歌不尽
    2021-02-14 12:45

    A static library has to contain every symbol defined in its source code, because it might get linked into an executable which needs just that specific symbol. But once it is linked into an executable, we know exactly which symbols end up being used, and which ones don't. So the linker can trivially remove unused code, trimming the file size by a lot. Similarly, any duplicate symbols (anything that's defined in both the static library and the executable it's linked into gets merged into a single instance.

提交回复
热议问题