Samuel Samuel - 1 year ago 75
Linux Question

What is the 'soname' option for building shared libraries for?

I learned the "Program Library HOWTO". It mention that using

to manage the version like follow.

gcc -shared -fPIC -Wl,-soname, -o foo.c
ln -s
ln -s

And I get the information that if the
is not set. it will be equal to ,see the answer from here.

And I find that it also can work without soname , like following

gcc -shared -fPIC -o foo.c
ln -s
ln -s

So I think that the only one useful point is that the
option can tell you the version of the shared library when you use
readelf -d
command to check it.

What else can it do?

Answer Source

soname is used to indicate what binary api compatibility your library support.

SONAME is used at compilation time by linker to determine from the library file what actual target library version. gcc -lNAME will seek for link or file then capture its SONAME that will certainly be more specific ( ex links to that contains SONAME ).

At run time it will link with this is then set into ELF dynamic section NEEDED, then a library with this name ( or a link to it ) should exists. At Run time SONAME is disregarded, so only the link or the file existence is enough.

Remark: SONAME is enforced only at link/build time and not at run time.

'SONAME' of library can be seen with 'objdupmp -p file |grep SONAME'. 'NEEDED' of binaries can be seen with 'objdupmp -p file |grep NEEDED'.

[EDIT] WARNING Following is a general remark, not the one deployed in linux. See at the end.

Let's assume you have a library with name and you develop a new libnuke library :

  • if your new library is a fix from previous without api change, you should just keep same soname, increase the version of filename. ie file will be but soname will still be
  • if you have a new library that only added new function but didn't break functionality and is still compatible with previous you would like to use same soname than previous plus a new suffix like .1. ie file and soname will be Any program linked with libnuke.1.2 will still work with that one. New programs linked with libnuke.1.2.1 will only work with that one ( until new subversion come like libnuke. ).
  • if your new library is not compatible with any libnuke :
  • if your new library is compatible with bare old version : [ ie still compatible with ]

[EDIT] to complete : linux case.

In linux real life SONAME as a specific form : lib[NAME][API-VERSION].so.[major-version] major-version is only one integer value that increase at each major library change. API-VERSION is empty by default


Then real filename include minor versions and subversions ex :

I think that not providing a soname is a bad practice since renaming of file will change its behavior.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download