简体   繁体   English

C中的共享库和二进制文件

[英]Shared libraries and binaries in C

I took over a fairly large C code. 我接手了一个相当大的C代码。 There are lots of legacy binaries that are requiring old version shared libraries. 有许多遗留二进制文件需要旧版本的共享库。 The server has never versions of those exact libraries. 服务器从来没有那些确切库的版本。 I could recompile or setup symbolic links that will connect older versions to new. 我可以重新编译或设置将旧版本连接到新版本的符号链接。 Setting up symbolic links will take some time - is there any standard or smart way to do this? 设置符号链接需要一些时间 - 是否有任何标准或智能方法来执行此操作? I am new to this and would appreciate any tips. 我是新手,非常感谢任何提示。 This is all C and FreeBSD environment. 这是所有C和FreeBSD环境。

Thanks. 谢谢。

In general when updating legacy code with new libraries, it is best to perform a check by recompiling the source code against the new libraries and their includes. 通常,在使用新库更新遗留代码时,最好通过针对新库及其包含重新编译源代码来执行检查。 This will allow you to use the compiler to check for inconsistencies between the old and new libraries in areas such as data types, function signatures, etc. 这将允许您使用编译器检查旧库和新库之间在数据类型,函数签名等方面的不一致性。

By recompiling you also are able to check that the new libraries provide all of the dependencies that you need. 通过重新编译,您还可以检查新库是否提供了所需的所有依赖项。

Finally, doing a recompile will help you check that you are in fact able to recompile and link everything and have all of the necessary components. 最后,重新编译将帮助您检查您实际上是否能够重新编译和链接所有内容并拥有所有必需的组件。

I would feel uncomfortable tying to take a short cut such as using symbolic links. 如果使用符号链接,我会觉得不舒服。

The shared-library version number is only supposed to be changed when the ABI changes. 只有在ABI更改时才应更改共享库版本号。 (Old versions of FreeBSD didn't quite get this right, and it's fixed in more recent versions but only for system libraries!) So the only way to make those applications work properly is to either recompile them, or supply the exact version of the shared library that they were linked against. (FreeBSD的旧版本没有完全正确,并且它已在更新的版本中修复,但仅适用于系统库!)因此,使这些应用程序正常工作的唯一方法是重新编译它们,或者提供确切版本的他们被链接的共享库。 For programs that only depend on old versions of the FreeBSD system libraries, you can installes the compat[45678]x packages, which provide the versions of the libraries supplied with the specified version of the OS -- but there are significant pitfalls: 对于仅依赖于旧版FreeBSD系统库的程序,您可以安装compat [45678] x软件包,它们提供随指定版本的操作系统提供的库的版本 - 但是存在重大缺陷:

1) If some of the libraries your application depends on are linked against newer versions of the standard libraries than your application itself is, the dynamic linker will give you two incompatible copies of the standard library, and things are not likely to work. 1)如果您的应用程序所依赖的某些库与标准库的新版本链接而不是您的应用程序本身,则动态链接器将为您提供标准库的两个不兼容的副本,并且事情不太可能起作用。

2) If your application loads external modules or plug-ins using dlopen(), all bets are off, because these modules are not versioned. 2)如果您的应用程序使用dlopen()加载外部模块或插件,则所有投注均已关闭,因为这些模块未进行版本控制。

FreeBSD 8 and newer use symbol versioning for the C library and some other important system libraries, so those libraries should never change library version again and ABI compatibility will be preserved. FreeBSD 8和更新版本对C库和其他一些重要的系统库使用符号版本控制,因此这些库不应再次更改库版本,并且将保留ABI兼容性。 Many third-party developers are not so careful, and will both break ABI without changing the library version, and change the library version without breaking the ABI, so you can't win. 许多第三方开发人员都不是那么小心,并且会在不更改库版本的情况下破坏ABI,并在不破坏ABI的情况下更改库版本,因此您无法获胜。 (Some developers don't read the documentation and think that the shared-library version number should be the same as the product's version number.) (某些开发人员不会阅读文档,并认为共享库版本号应与产品的版本号相同。)

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

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