1

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.

Ales100
  • 153
  • 1
  • 8

1 Answers1

1

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!

Yujian Yao - MSFT
  • 945
  • 1
  • 3
  • 9
  • You probably reacted to my previous question related to static libraries. Static libraries export functions should be visible using `dumpbin /SYMBOLS` as was discussed in the link above (inside question). In this case I only tried to see exported functions using dumbin, no linking to .dll at all. But I think that the answer that you cited is not correct, because if you force to avoid linker optimization, it is possible to view linked .lib functions inside .dll using dumpbin. It is also logical, linking .lib to .dll = adding code to .dll. – Ales100 Apr 25 '22 at 06:34
  • Hi @Ales100, I sugget you try to set "Use Library Dependency Inputs" to true for lib1.lib, and you could also refer to this [issue](https://stackoverflow.com/questions/47817660/exporting-functions-from-a-win32-cross-built-static-library). – Yujian Yao - MSFT Apr 25 '22 at 08:33
  • No, I applied this only to static library to check if all symbols are added. I wanted this to verify that part of the static library is fine and everything is visible. Unfortunately, dumpbin didn't confirmed my expectations. – Ales100 Apr 25 '22 at 08:37
  • 1
    I see that your output is not consistent with the sample, the [documentation](https://learn.microsoft.com/en-us/cpp/build/reference/symbols?view=msvc-170) mentions: This option displays the COFF symbol table. Symbol tables exist in all object files. A COFF symbol table appears in an image file only if it is linked with /DEBUG. – Yujian Yao - MSFT Apr 26 '22 at 08:53
  • 1
    You are correct that this dumpbin option does a little bit different things. But correct option is obviously `dumpbin /LINKERMEMBER`, to see "exports" (public functions). – Ales100 Apr 26 '22 at 10:57