Search code examples
linuxgccshared-librariesnm

nm output of show the shared library's version is incorrect


I just have built a shared library, but when I use nm command to look the dependency the output is as below

$ nm -a libgio-2.0.so.0.2701.0 | grep ZLIB
     U deflateSetHeader@@ZLIB_1.2.2
     U inflateGetHeader@@ZLIB_1.2.2

I don't know the mean of @@ZLIB_1.2.2, actually the command of building libgio is

gcc -o libgio-2.0.so.0.2701.0   libfoo.so libbar.so libz.so.1.2.8

where libz.so.1.2.8 is built from source by myself and put to the same directory of libgio-2.0.so.0.2701.0. It's not the same version as the system's libz(/usr/lib/libz.so)

So, my question is why the nm output of @@zlib is 1.2.2, not 1.2.8? and what the mean of @@ZLIB_1.2.2 in nm output?

Thanks


Solution

  • nm is showing versioned symbols and the version is not wrong.

    So, my question is why the nm output of @@zlib is 1.2.2, not 1.2.8?

    Because that's the version of the symbol in the library you linked to. The version of a symbol doesn't have to be the same as the version of the library.

    and what the mean of @@ZLIB_1.2.2 in nm output?

    It means that the current definition of the deflateSetHeader symbol was added in version 1.2.2

    It is still the same in version 1.2.8 because those versions of the zlib library are compatible. Version 1.2.8 provides the same symbols as version 1.2.2 and they are compatible. The new library might also provide some extra symbols as well, which would have version ZLIB_1.2.2, but your library doesn't use them so you don't see any reference to them in the nm output.

    Basically everything is OK, there's nothing to worry about. Your program needs the symbols from version 1.2.2 and the library you have provides those symbols.