Windows Static Library with Default Functions

旧城冷巷雨未停 提交于 2019-12-01 20:26:26

问题


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.


回答1:


I figured out a solution (not sure if it is the only or best solution).

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.



来源:https://stackoverflow.com/questions/5097961/windows-static-library-with-default-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!