tedtoal
tedtoal

Reputation: 1080

Linux accommodates multiple versions of a shared library but what about includes?

I'm trying to understand how shared library versions are managed under Linux and how these interact with different versions of include files when configuring and compiling a program.

I understand that a system can have multiple versions of shared libraries (.so files) differing by the first version number following libxxx.so in the filename, and that different programs may have been linked with different versions of the same library. A new version of a library (.so.# has changed) is generally incompatible with the previous version. (Version numbers after the first are minor library changes not affecting its compatibility).

If I am compiling (or recompiling) an older program which has been linked with an older version of a library, and if I have both the older and newer libraries on my system, there seems to be no mechanism for managing multiple versions of the include files that are associated with each library version. Thus, even though I have the older version of the library available, without the older version of the include files to link to, I really can't recompile that program. Is that true?

If so, support of multiple library versions seems to be of questionable value. The idea must be that the only users of old versions of libraries are programs that were compiled when the old version was current, and that no program should ever be recompiled unless all the versions of all the libraries it links with are the most recent versions of those libraries installed on the system. As soon as a new version of a library is installed, all programs using the older version can no longer be compiled (unless they are updated to newer version using the newer library). Right?

Or, do people commonly go to the trouble of keeping a separate subdirectory of include files for each version of each library that is installed, so programs can be recompiled using the appropriate include file and library versions?

Upvotes: 2

Views: 2357

Answers (1)

Thomas Dickey
Thomas Dickey

Reputation: 54524

Include-files are handled differently from shared libraries:

  • With shared libraries, there will be one name for development packages to use when linking, which is a symbolic link to a file which has a specific soname (name plus version). After linking, a program has a reference to that file which is used whenever running the program.

  • Include-files can be distinguished by the -I option for include-paths. When there are multiple useful versions of a library, some developers may package the versions using different directory names for holding the related header files. That way, changing just the -I option when compiling makes the build scripts able to work with a specific version of the headers. But unlike shared libraries, the header files are used only when building the program which uses a library.

Upvotes: 1

Related Questions