Is there a way to determine the c / C ++ library version?

For example, how to get the version of /usr/lib/libz.a? It will be great if you can get other useful information, such as compiler / arch, etc.

The reason I want to know this is because gcc always says that it ignores the libz that I suggested on the command line when I compile my program and associated with a specific version of libz. gcc thinks /usr/lib/libz.a is correct.

+3
source share
5 answers

C libraries do not have their own version control system. At best, the library has a symbol.

+6
source

Answer on Linux / Unix Elf:

.a ar ( tar zip, ), , , . . - , .o. ar:

ar -t /usr/lib/libz.a

objdump:

objdump -a /usr/lib/libz.a

(.so), - . readelf dumpelf elfutils, , , libc, .. . man readelf .

+2

Mac OS X otool, , ( lipo -info, , arch). :

$otool -L /usr/lib/libz.dylib 
/usr/lib/libz.dylib:
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 123.0.0)

otool -L , ( " " ), - "" , . , Mac.

+1

#, -a _ | grep ' '. , , , rpm ( , , , ).

+1

On Linux systems (for example), the version is usually found in the name.
This seems to be hidden since the libraries you link to are symbolically linked to a specific version:

> ls -l /usr/lib/libncurses.dylib
lrwxr-xr-x  1 root  wheel  20 Feb 28 16:08 libncurses.dylib -> libncurses.5.4.dylib

Therefore, when you reference -lncurses, the compiler actually refers to the libncurses.5.4 link in the application. If you look at the symbol table in the application, you will see that it actually stores very specific version information for each lib, and not the general version with which it was associated.

0
source

Source: https://habr.com/ru/post/1739077/


All Articles