简体   繁体   English

为什么可执行文件小于与应用程序项目静态链接的库?

[英]why executable is smaller than the library which is statically linked with application project?

I have created windows application project in visual studio. 我已经在Visual Studio中创建了Windows应用程序项目。 OpenSSL library (Size: 15Mb) is statically linked with application project. OpenSSL库(大小:15Mb)与应用程序项目静态链接。

But, Still size of application (executable file) .exe file ~ 2 MB only. 但是,应用程序(可执行文件).exe文件的大小仍然只有2 MB。

How is it possible? 这怎么可能? Can anyone explain me how linker do that ? 谁能解释一下链接程序是怎么做的?

During linking, the linker will only pick the code from the OpenSSL library that is needed by your application. 在链接期间,链接器将仅从应用程序需要的OpenSSL库中选择代码。 It will not include the entire OpenSSL library. 它不会包括整个OpenSSL库。 Therefore, your executable can be considerably smaller than the library. 因此,您的可执行文件可能比库小得多。

Basically, a static library is just a container of object files. 基本上,静态库只是对象文件的容器。 Each object files contains the code for a single compilation unit. 每个目标文件都包含一个编译单元的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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