具有默认功能的Windows静态库 [英] Windows Static Library with Default Functions
问题描述
我想在Windows中创建一个静态库(.lib),该库可以在后续构建中用作未定义函数的备份".
I would like to create a static library (.lib) in Windows that can be used in subsequent builds as a "backup" for undefined functions.
例如,假设我有foobar.lib,它具有以下定义:
For instance let's say I have foobar.lib which has definitions for:
FOO
BAR
我还有一些其他程序,它们仅定义FOO
并将被构建到必须导出FOO
和BAR
的DLL中.我希望能够使用foobar.lib在生成的DLL中自动导出BAR
的默认定义(并忽略foobar.lib中FOO
的定义).
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).
我尝试将foobar.lib发送到链接器,但是遇到了多个定义的符号错误(/FORCE应该重写该错误,但强烈警告说它可能无法按预期工作).我还尝试使用/NODEFAULTLIB:foobar.lib,但随后它会完全忽略该库,并说BAR
未定义.
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.
我几乎100%肯定有一种方法可以执行此操作,因为我使用的是执行此操作的应用程序(Abaqus),允许用户编写插件,而不必为该插件定义所有必需的导出DLL.而且他们不使用/FORCE选项.
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.
推荐答案
我想出了一个解决方案(不确定是唯一的还是最佳的解决方案).
I figured out a solution (not sure if it is the only or best solution).
我试图使用一个目标文件(foobar.obj)在foobar.lib中定义FOO
和BAR
.如果我将其拆分为foo.obj和bar.obj,然后使用它们创建foobar.lib,则链接程序可以有效地忽略相应的.obj文件.
I was trying to define FOO
and BAR
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.
这篇关于具有默认功能的Windows静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!