我想问一个问题,为什么dumpbin看不到导出的静态库函数?
下面是使用预编译头(VisualStudio2017)编写的x86 C++静态库(版本)代码:
H(尝试了两个错误的名称和没有):
/*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
我应用dumpbin命令(开发人员命令提示符for VS 2017 (也包括x86)),它应该给出导出函数的表:
dumpbin /SYMBOLS "C:\\pathToLibrary\\StaticLibrary.lib"
根据How to See the Contents of Windows library (*.lib),这应该是正确的命令
输出如下(包括损坏的名称和未损坏的名称):
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
如果我将dumpbin \export
应用于DLL,它的工作原理就像一种魅力。
这个问题对我来说非常重要,因为我目前正在解决静态库的链接问题。
发布于 2022-04-22 01:51:08
关于你的问题,这种现象是一种预期的行为。由于详细的原因,请仔细阅读本issue。
就导入的符号而言,使用dumpbin,您可以看到所谓的imported和imported,这两个表(通常都存在),只要应用程序导入了至少一个函数(在您的例子中是
)。由于您的应用程序从静态库(在您的例子中是B.lib)导入一个函数,所以在上面提到的导入表中没有从B.lib中使用的函数的条目。一旦库静态地链接到应用程序,它的主体(代码)就是应用程序的一部分。除了应用程序的函数使用dumpbin不可见外,静态库的函数在dumpbin!
中也不可见。
https://stackoverflow.com/questions/71954552
复制相似问题