简体   繁体   English

链接程序包括整个库到.exe文件还是仅包括该库中程序中使用的功能?

[英]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.

相关问题 使用库将库包含与程序分离 - Separating Library Includes From Program Using Library 静态链接时,链接器是否包含整个库? - When linking statically, does the linker include the whole library? g ++链接器未定义共享库中仅对某些功能(不是全部)的引用 - g++ linker undefined reference to only some functions (not all) from shared library 为什么库中的此模板类在使用时会生成链接器错误? - Why does this template class in a library generate linker errors when used? 我的程序实际上是否依赖于链接的库,但是没有使用库中的函数? - Does my program actually depends on library that is linked against, but no function from library is used? dll链接静态库-未使用函数中未解析的链接器符号 - dll linking static library - unresolved linker symbols from unused functions 这个仅标头的库如何防止链接程序问题? - How does this header-only library guard against linker problems? 链接器删除库,无法识别 - linker delets library and does not recognize it 将仅标头库的包含文件包装在单个cpp文件中 - Wrap the includes of a header-only library in a single cpp file 警告:链接器路径没有库-lpthread的真实文件 - Warning: linker path does not have real file for library -lpthread
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM