The version info in not explicitly stored in an ELF file. What you have in there is the name of the library, the
soname, which includes the major version.
The full version is usually stored as a part of the library file name.
If you have library, say
libtest.so, then you usually have:
libtest.so.1.0.1 - The library file itself, containing the full version
libtest.so.1 - Symlink to
libtest.so.1.0.1, having the same name as
libtest.so - Symlink to
libtest.so.1 used for linking.
In the library file
libtest.so.1.0.1, there will be an entry called
SONAME in dynamic section, that will say this library is called
libtest.so.1. When you link a program against this library, the linked program will store the
soname of the library under
NEEDED entry in the dynamic section.
If you want to verify, what exactly is in which ELF file, you can try to run:
readelf -a -W elffile
elffile can be either an library of an executable.
If you simply want to get the library version, you can play with:
readelf -d /path/to/library.so |grep SONAME
AFAIK, there's no such info (at least not by default) in executable files.
Or you can rely on the program itself or your packaging system, as Rahul Patil wrote.