简体   繁体   English

程序如何依赖 Linux 中的共享库?

[英]How does program depend on shared library in Linux?

I was taught the advantage of shared library over static library is that if I modify library source code, only shared library must be rebuilt whereas both library and program must be rebuilt in case using static library.我被告知共享库相对于 static 库的优势在于,如果我修改库源代码,则必须重建共享库,而在使用 static 库的情况下,必须重建库和程序。

Today, I made some change in library and rebuilt the *.so file.今天,我对库进行了一些更改并重建了 *.so 文件。 However, the program loads new shared library and crash, I have to rebuild the program with new shared library to make it work.但是,程序加载新的共享库并崩溃,我必须使用新的共享库重建程序才能使其工作。 So my question is that:所以我的问题是:

1) How does program load the shared library? 1)程序如何加载共享库? Why do I have to build the program again?为什么我必须重新构建程序?

2) How about other libraries that depend on modified library, do I have to rebuild them too? 2)其他依赖于修改库的库怎么样,我也必须重建它们吗?

When using a new shared library with an old program, there's rules about what sort of changes the shared library can make to avoid breaking ABI compatibility.将新的共享库与旧程序一起使用时,对于共享库可以进行哪些更改以避免破坏 ABI 兼容性,有一些规则。 For example, it can add new functions and change the body of existing functions, but it can't remove functions or change the signature of existing functions.例如,它可以添加新函数和更改现有函数的主体,但不能删除函数或更改现有函数的签名。 When other people make shared libraries, they take care of keeping track of this for you with versioning.当其他人创建共享库时,他们会通过版本控制为您跟踪这些内容。 If you're going to make your own, you need to keep track of this yourself.如果您要自己制作,则需要自己跟踪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM