具有默认函数的 Windows 静态库 [英] Windows Static Library with Default Functions

查看:23
本文介绍了具有默认函数的 Windows 静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 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 并且将被构建到必须导出 FOOBAR 的 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) 来允许用户编写插件,而不必为插件定义所有必需的导出动态链接库.而且他们不使用/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 中定义 FOOBAR.如果我将其拆分为 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆