— Based on https://unix.stackexchange.com/questions/475/how-do-so-shared-object-numbers-work
In my work projects, most of the linux SO files have a suffix like libsolclient_jni.so.1.7.2. This is to support two executables using different versions of a SO at the same time.
Q: How is the linker able to find this file when we give linker a command line option like “-lsolclient_jni”? In fact, java System.loadLibrary(“solclient_jni”) follows similar rules. That’s why this example uses a java native library.
A: Actually, linker (at link time) and dynamic loader (at run time) follow different rules
- at compile time, executable binaries saves (hardcoded) info about which version of a SO to load into memory. You can run “ldd /the/executable/file” to reveal the exact versions compiled with the executable.
- at run time, executable would consult the hardcoded info and load libsolclient_jni.so.1.7.2 into memory
- at link time, linker only uses the latest version. So there’s usually a symlink like libsoclient_jni.so (without suffix)
— static libraries:
I think static libraries like libc.a do not have this complexity.
During static linking the linker copies all library routines used in the program into the executable image. This of course takes more space on the disk and in memory than dynamic linking. But a static linked executable does not require the presence of the library on the system where it runs.