[英]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(). 假设有一个名为player的库,它具有两个名为footballer()和cricketer()的函数,并且在程序中我们仅使用了footballer()。
Will the linker link both function to exe or only the used function ie football()... 链接器会将两个函数都链接到exe还是仅将使用的函数(例如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. 诸如Linux,Mac OS X和Windows之类的主要平台上的几乎所有链接器都可以丢弃未使用的代码,但是对于几乎所有这些链接器来说,这都是一个选择。 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. 在某些实现中,库由许多目标文件组成,并且链接程序在目标文件而非功能上运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.