简体   繁体   中英

does the linker includes whole library to .exe file or only the functions used in program from that library?

Say, a library , named player, has two functions named footballer() and cricketer(), and in program we only used footballer().

Will the linker link both function to exe or only the used function ie football()...

In general undefined. First let's assume we talk about static library.

Almost any linker on main platfroms like Linux, Mac OS X and Windows can throw away not used code, but for almost all them this is a option. So this option can be turn on or off.

Plus modern compilers have link time optimization pass, during which as not direct effect not used code will be removed.

This greatly depends on implementation and linker options. Some linkers will link only the code of the used function while others will link both.

In some implementations the libraries consist of many object files, and linkers operate on the level of object file, not function.

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