5

When I run lib /list mylib.lib I see some contained .obj files, but no information about the functions similar to this:

Path\file1.obj
Path\file2.obj
Path\file3.obj

If I open the .lib file as an archieve I can see that there are a number of files 1.txt, ..., n.txt in addition to the object files. Those txt files seem to contain information about the functions in the .obj files on the format:

:
Path\file1.obj    ?function_name@...
:

Thus some info can be retrieved that way.

But isn't there a better way to get the function info ? For example using lib.exe, dumpbin.exe or another tool ? Also in a more readable/demangled format ? So far I had no luck finding that.

There is a related question here but it does not discuss what to do with object files contained in a .lib file.

Community
  • 1
  • 1
Zitrax
  • 19,036
  • 20
  • 88
  • 110
  • Does my answer showing use of ``/symbols`` with ``dumpbin`` or the other tool ``undname`` answer your question? – Phil Jul 14 '15 at 19:07
  • Does this answer your question? [How to See the Contents of Windows library (\*.lib)](https://stackoverflow.com/questions/305287/how-to-see-the-contents-of-windows-library-lib) – StayOnTarget Jul 06 '21 at 18:32

2 Answers2

10

You need to use dumpbin. (See dumpbin on msdn for more information.)

dumpbin /symbols /exports mylib.lib

You can also use dumpbin followed by undname. (See undname.) For example:

dumpbin /all /exports mylib.lib > mylib.txt
undname mylib.txt

Of course you need to do this from a command prompt from which the Visual Studio tools are in your path. With my install dumpbin and undname are at:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\amd64\dumpbin.EXE
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\amd64\undname.EXE

A Visual Studio Command prompt is available from the program menu. But I get one by simply calling

"%VS120COMNTOOLS%..\..\vc\vcvarsall" amd64
Phil
  • 5,822
  • 2
  • 31
  • 60
  • The only output from `dumpbin /symbols /exports` is `File Type: LIBRARY`. This was mentioned in the question I linked to which did not help me. – Zitrax Jul 15 '15 at 06:06
  • Is this lib for a dll? If so, then you will have exported symbols only for what you explicitly export. I typically do this using ``__declspec(dllexport)``. Try using dumpbin on the MS supplied msvcrt.lib in ``"%VS120COMNTOOLS%\..\..\vc\lib`` – Phil Jul 16 '15 at 14:14
2

GNU nm does what you want, should work with MSVC objects too as long as you don't compile with /LTCG.

$ nm ssleay32MT.lib 
tmp32/tls_srp.obj:
[...]
00000000 R ??_C@_0BA@IKHGPLLJ@?4?2ssl?2tls_srp?4c?$AA@
         U @__security_check_cookie@4
00e0797d a @comp.id
80000191 a @feat.00
         U ___security_cookie
         U __chkstk
         U _BN_bin2bn
         U _BN_bn2bin
         U _BN_clear_free
         U _BN_copy
         U _BN_dup
         U _BN_free
         U _BN_num_bits
         U _BN_ucmp
         U _BUF_strdup
         U _CRYPTO_free
         U _CRYPTO_malloc
         U _ERR_put_error
         U _OPENSSL_cleanse
         U _RAND_bytes
         U _SRP_Calc_A
00000000 T _SRP_Calc_A_param
         U _SRP_Calc_B
         U _SRP_Calc_client_key
         U _SRP_Calc_server_key
         U _SRP_Calc_u
         U _SRP_Calc_x
         U _SRP_check_known_gN_param
         U _SRP_create_verifier_BN
00000000 T _SRP_generate_client_master_secret
00000000 T _SRP_generate_server_master_secret
[...]
Thomas
  • 3,074
  • 1
  • 25
  • 39
  • When running `nm` on the file I get the contained object files listed followed by `: File format not recognized`. – Zitrax Jul 15 '15 at 06:11
  • @Zitrax: Did you disable LTCG (Link Time Code Generation)? – Thomas Jul 15 '15 at 07:41
  • I get the same output regardless of that option. – Zitrax Jul 15 '15 at 08:18
  • @Zitrax: It works for me, see my updated answer. Ensure your `nm` was built for the x86_64 target. – Thomas Jul 15 '15 at 08:51
  • Hm, I did indeed have the 32 bit version, but after some looking I could not find a prebuilt 64 bit nm binary. – Zitrax Jul 15 '15 at 09:05
  • @Zitrax: Install MSYS2 + MinGW (a 32 bit MinGW is sufficient), then build binutils with `--target=x86_64-w64-mingw32`. Or if you trust me enough (the binaries are 32-bit, but the target is indeed x86_64): http://92.222.216.113/thomas/x86_64-w64-mingw32-binutils-2.25.zip (sha256: d341aa2395caf18e657268a935244f382a9f04f9c955c8477e2f586d1d94d0aa). – Thomas Jul 15 '15 at 09:35
  • Still the same message. – Zitrax Jul 15 '15 at 09:55
  • @Zitrax: Are you **100%** sure the generated objects are native and not `/LTCG` or similar? Extract the objects with 7zip or AR, then check the file header, should be `0x8664` (or `64 86` in hex view) for native x86_64 objects. – Thomas Jul 15 '15 at 10:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/83412/discussion-between-zitrax-and-thomas). – Zitrax Jul 16 '15 at 09:32