为什么我应该只为更新库而重新编译整个程序? [英] Why should I recompile an entire program just for a library update?

查看:78
本文介绍了为什么我应该只为更新库而重新编译整个程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于以下链接: http://www.archlinux.org/news/libpnglibtiff-rebuilds -move-from-testing/

有人可以向我解释为什么在其中一个库已更新后应该重建程序吗?

Could someone explain to me why a program should be rebuilt after one of its libraries has been updated?

由于主"文件根本没有更改,这有什么意义?

How does that make any sense since the "main" file is not changed at all?

推荐答案

如果所涉及功能的签名未更改,则重建"程序意味着必须链接再次.您无需再次编译.

If the signatures of the functions involved haven't changed, then "rebuilding" the program means that the object files must be linked again. You shouldn't need to compile them again.

API是合约,描述了库中公共功能的接口.当编译器生成代码时,它需要知道什么类型的变量以及以什么顺序传递给每个函数.它还需要知道返回类型,因此它知道将从函数返回的数据的大小和格式.编译代码时,库函数的地址可能表示为库的开头加上140字节".编译器不知道绝对地址,因此仅指定距库开头的偏移量.

An API is contract that describes the interface to the public functions in a library. When the compiler generates code, it needs to know what type of variables to pass to each function, and in what order. It also needs to know the return type, so it knows the size and format of the data that will be returned from the function. When your code is compiled, the address of a library function may be represented as "start of the library, plus 140 bytes." The compiler doesn't know the absolute address, so it simply specifies an offset from the beginning of the library.

但是库中,功能的内容(即实现)可能会发生变化.发生这种情况时,代码的长度可能会更改,因此函数的地址可能会更改.链接器的工作是了解每个函数的入口点所在的位置,并将这些地址填充到目标代码中以创建可执行文件.

But within the library, the contents (that is, the implementations) of the functions may change. When that happens, the length of the code may change, so the addresses of the functions may shift. It's the job of the linker to understand where the entry points of each function reside, and to fill those addresses into the object code to create the executable.

另一方面,如果库中的数据结构发生了变化,并且库要求调用者管理内存(这是一种不好的做法,但不幸的是很常见),那么您需要重新编译代码,以便它可以解释更改.例如,如果您的代码使用malloc(sizeof(dataStructure))为大小加倍的库数据结构分配内存,则您需要重新编译代码,因为sizeof(dataStructure)的值将更大.

On the other hand, if the data structures in the library have changed and the library requires the callers to manage memory (a bad practice, but unfortunately common), then you will need to recompile the code so it can account for the changes. For example, if your code uses malloc(sizeof(dataStructure)) to allocate memory for a library data structure that's doubled in size, you need to recompile your code because sizeof(dataStructure) will have a larger value.

这篇关于为什么我应该只为更新库而重新编译整个程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆