4

A few months ago, I built a C software that used libxml2 as a shared library, on a debian. I created a .deb file for installation of the software, and Ubuntu users could make it run.

Today, the latest version of Ubuntu has a greater version of libxml2. So now, the software doesn't run, it asks for a previous version of libxml2 and the only way to make it work is building the software while linking on the new version of libxml2.

So my question is, is it possible to link against a shared library without requiring a specific version (taking the risk the software could not work on some version) ?

If it's not, then what is the real advantage of linking with a shared library if you can't deploy your software on any Linux distribution ?

Thanks for help.

Best regards, Vincent.

Vincent
  • 165
  • 10
  • As already commented, the (accepted) answer below doesn't answer the question. I assume the root question really is: How do you override the SONAME recorded in the binary so it doesn't contain a major number - "libxml2.so" instead of "libxml2.so.2". I don't know if it even works since the library has a SONAME with the major number ... – hansfn Jul 11 '19 at 09:27

1 Answers1

3

Most shared libraries will have an embedded SONAME. This SONAME is used to indicate binary compatibility. For example, libxml2.so.2.7.8 has an embedded SONAME of libxml2.so.2:

readelf -Wa libxml2.so.2.7.8 | grep SONAME
0x000000000000000e (SONAME)             Library soname: [libxml2.so.2]

If libxml2.so.2.7.9 came out, it would likely still be binary compatible with v2.7.8, and would still have an SONAME of libxml2.so.2 and your application would work just fine. Only when a change was introduced that broke binary compatibility would the SONAME get incremented, breaking your application.

If you want to create a package that will automatically work on all distributions, one approach is to deliver your own version of libxml2, then modify the LD_LIBRARY_PATH such that your version automatically gets loaded.

John Saxton
  • 530
  • 3
  • 14
  • 2
    "Every shared library has an embedded `SONAME`" -- that statement is false. It is *good practice* to have `SONAME`, but it is by no means required. – Employed Russian Nov 28 '13 at 18:01
  • 1
    this does not answer to the question "is it possible to link against a shared library without requiring a specific version?" – igor May 18 '18 at 15:37