C++库位于AdditionalDependencies中,但在dumpbin和dependencywalker中未列出。

huangapple go评论61阅读模式
英文:

C++ library is in AdditionalDependencies but is not listed by dumpbin nor dependencywalker

问题

在VS中,我有一个C++项目,生成一个dll,让我们称之为"A.dll"。
在A.dll >> 链接器 >> 附加依赖项下,有一个库的条目"B.lib"。
当我通过dumpbin或dependencywalker查看"A.dll"时,库"B.lib"没有列出来。

我尝试删除附加依赖项中的"B.lib",但这会导致A.dll出现链接错误。
这让我感到困惑。我期望库B.lib(显然被A.dll需要)应该被嵌入到A.dll中,并且可以通过"dumpbin /dependents"或类似的工具看到。

我是C++的新手,正在尝试理解这是如何可能的。也许有人可以解释一下。

英文:

I have a C++ project in VS, producing a dll, let's call it "A.dll".
Under A.dll >> Linker >> AdditionalDependencies, there is an entry for a library "B.lib".
When I put "A.dll" through dumpbin or depencencywalker, the library "B.lib" is not listed.

I've tried to remove "B.lib" from AdditionalDependencies, but it causes a liker error with A.dll.
This is confusing. I'd expect that library B.lib (which is obviously required by A.dll) should be embedded into A.dll and be visible via "dumpbin /dependends" or similar tools.

I am new to C++ and trying to understand how it is possible. Maybe somebody could explain.

答案1

得分: 0

B.lib 似乎在第一眼看起来是一个静态库。如果是这样的话,这意味着在链接时,从 B.lib 需要的内容会被复制到可执行文件 (A.dll) 中。在运行时,不再依赖于 B.lib

像 Dependency Walker 这样显示的依赖关系是动态链接库 (DLLs)。对于 DLL,你会有一个 .lib 文件,但它只包含函数的存根,足以告诉链接器如何在可执行文件中创建一个记录,以找到并使用来自 DLL 的适当函数。然后在运行时,用户需要拥有适当的 DLL 的副本才能实际使用该函数。当你启动可执行文件时,Windows 加载器不仅将可执行文件加载到内存中,还会加载所有它所需的 DLL。

英文:

At least at first glance, this sounds like B.lib is a static library. If so, that means whatever's needed from B.lib is replicated into the executable (A.dll) at link time. At run time, there's no longer any dependency on B.lib.

The dependencies that show up with something like Dependency Walker are dynamic link libraries (DLLs). With a DLL, you'll have a .lib file, but all it contains are basically stubs of functions--enough information to tell the linker how to create a record in your executable to find and use the appropriate function from the DLL. Then at run-time, the user needs a copy of the appropriate DLL to actually use the function. When you start the executable, the Windows loader not only loads your executable file into memory, but also loads all the DLLs it needs.

huangapple
  • 本文由 发表于 2023年6月6日 08:19:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76410707.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定