Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking with a shared library without version

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.

like image 804
Vincent Avatar asked Nov 01 '25 16:11

Vincent


1 Answers

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.

like image 96
John Saxton Avatar answered Nov 03 '25 08:11

John Saxton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!