Dumpbin does not show symbols of Visual Studio C++ static library function

1.6k views Asked by At

I would like to ask a question, why are not exported static library functions visible to dumpbin?

I have following code of x86 C++ static library (Release) using precompiled headers (Visual Studio 2017):

StaticLibTest.h (tried both mangled names and without):

/*extern "C"*/ __declspec(dllexport) void fnStaticLibTest();

StaticLibTest.cpp

#include "pch.h"
void fnStaticLibTest(){
    printf("Static library from another project.\n");
}

pch.h:

#ifndef PCH_H
#define PCH_H
#include <stdio.h>
// add headers that you want to pre-compile here
#include "StaticLibrary.h"

#endif //PCH_H

I apply command of dumpbin (Developer Command Prompt for VS 2017 (also x86)), which should gave me table of exported functions:

dumpbin /SYMBOLS "C:\\pathToLibrary\\StaticLibrary.lib"

This should be right command according to How to See the Contents of Windows library (*.lib)

The output is following (for both mangled and not mangled names):

Microsoft (R) COFF/PE Dumper Version 14.16.27045.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file C:\\pathToLibrary\\StaticLibrary.lib

File Type: LIBRARY

If I apply dumpbin \export to DLL, it works like a charm.

This problem is very important to me, because I am currently solving problem with linking of static libraries.

1

There are 1 answers

5
Yujian Yao - MSFT On

Regarding your question, the phenomenon is an expected behavior. For detailed reasons, please read this issue carefully.

As far as the imported symbols are concerned, using dumpbin, you can see the so called Import Address Table and the Import Name Table which both (typically) exist as soon as at least one function is imported by an application (in your case A.dll). Since your application imports one function from a STATIC library (in your case B.lib), NO entry exist in the imports tables mentioned above for the functions used from B.lib. Once a library is STATICALLY linked to an application, its body (code) is part of the application. As well as the functions of your application are not visible using dumpbin, the functions of the static library are not visible to dumpbin!