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

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

问题描述

关于以下链接: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天全站免登陆