0

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

Peng Li
  • 3
  • 2

1 Answers1

0

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.

Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521
  • 1
    You might clarify that the `ZLIB` is chosen by the developer when building the library, and that it is not necessarily the *name* of the library. – Thomas Dickey Jan 26 '16 at 21:25
  • Thanks Jonathan and Thomas for your detail comments. so @@version is not the actual linked library's version, but the version of the symbol. In my case, the program will still link zib 1.2.8, not 1.2.2, is this right? – Peng Li Jan 27 '16 at 02:10
  • The program will link to whatever you link it to (and what the runtime loader finds at runtime). Using `nm` can't tell you what library the program links to, it can only show you the missing symbols. `deflateSetHeader@@ZLIB_1.2.2` is just the name of a symbol (decorated with some extra information to make it different from e.g. `deflateSetHeader@@ZLIB_0.1.1`). To see what library the program links to, use `ldd` not `nm`. – Jonathan Wakely Jan 27 '16 at 11:25