具有默认函数的 Windows 静态库
我想在 Windows 中创建一个静态库 (.lib),可以在后续构建中用作未定义函数的“备份”。
例如,假设我有 foobar.lib,它具有以下定义:
FOO
BAR
我还有一些其他程序,仅定义 FOO
并且要构建到必须导出 FOO
的 DLL 中和BAR
。我希望能够使用 foobar.lib 自动导出生成的 DLL 中 BAR
的默认定义(并忽略 foobar.lib 中 FOO
的定义)。
我尝试将 foobar.lib 发送到链接器,但收到多个定义的符号错误(/FORCE 应该覆盖该错误,但强烈警告它可能无法按预期工作)。我也尝试过使用 /NODEFAULTLIB:foobar.lib 但随后它完全忽略该库并表示 BAR
未定义。
我几乎 100% 确定有办法做到这一点,因为我使用执行此操作的应用程序 (Abaqus) 来允许用户编写插件,而不必为插件 DLL 定义所有所需的导出。并且他们不使用 /FORCE 选项。
I would like to create a static library (.lib) in Windows that can be used in subsequent builds as a "backup" for undefined functions.
For instance let's say I have foobar.lib which has definitions for:
FOO
BAR
and I have some other program that defines FOO
only and is to be built into a DLL that must export FOO
and BAR
. I want to be able to use foobar.lib to automatically export the default definition of BAR
in the resulting DLL (and ignore the definition of FOO
in foobar.lib).
I have tried sending foobar.lib to the linker but I get a multiple defined symbols error (/FORCE is supposed to override that but with strong warnings that it probably won't work as expected). I've also tried using /NODEFAULTLIB:foobar.lib but then it completely ignores the library and says BAR
is undefined.
I am almost 100% certain there is a way to do this because I use an application that does this (Abaqus) to allow users to write plug-ins and not have to define all of the required exports for the plug-in DLL. And they do not use the /FORCE option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一个解决方案(不确定它是否是唯一或最好的解决方案)。
我试图使用一个目标文件(foobar.obj)在 foobar.lib 中定义
FOO
和BAR
。如果我将其拆分为 foo.obj 和 bar.obj,然后使用它们创建 foobar.lib,链接器可以有效地忽略相应的 .obj 文件。所以简短的答案是:静态库的每个目标文件一个函数。
I figured out a solution (not sure if it is the only or best solution).
I was trying to define
FOO
andBAR
in foobar.lib using one object file (foobar.obj). If I split it up into foo.obj and bar.obj and then use those to create foobar.lib the linker can effectively ignore the appropriate .obj files.So the short answer is: one function per object file for the static library.