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

473 Views Asked by At

I have created windows application project in visual studio. OpenSSL library (Size: 15Mb) is statically linked with application project.

But, Still size of application (executable file) .exe file ~ 2 MB only.

How is it possible? Can anyone explain me how linker do that ?

1

There are 1 best solutions below

2
On

During linking, the linker will only pick the code from the OpenSSL library that is needed by your application. It will not include the entire OpenSSL library. 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.