It is my understanding that Visual Studio library projects use two separate processes after compiling, depending on the "General/Configuration type" setting:
If "static library" is selected, all of the object files are bundled together into the final
.libfile, a static library.If "dynamic library" is selected, all of the object files are linked together, along with dependencies, and bundled into the final
.dllfile, a dynamic library. Meanwhile, all of the__declspec(dllexport)symbols are gathered, and used to generate a.libfile, the import library.
I would like to create a foo.lib/foo.dll pair, where foo.lib is both an import library for foo.dll and a static library on its own. I have considered the following leads:
Create two separate projects,
FooLibandFooDll, and uselib.exein a post-build step to merge both.libfiles. This sounds like the easiest option but requires splitting in half what should otherwise be a cohesive module.Create a single DLL project, let the default build process create
foo.dlland its import library. Then add custom build steps to manually gather the object files and bundle them into the import library with lib. This sounds messy, and I'm not sure what the duplicates will do.I've tried messing around with
.deffiles, but even afterdumpbining the resulting lib files I'm a bit perplexed by its behaviour. Also, it needs an explicit list of mangled symbols, which is impractical.
Is there a simpler way to achieve that hybrid .lib/.dll combo? Otherwise, which lead should I rather follow?
Background
This module will be used in several .dlls and one .exe linked together. I need to have a single instance of half of its data in the resulting process at runtime (which is achieved by the .dll, since it will be only loaded once), while the other half is duplicated into each .dll or exe and initialized therein (which is achieved by the .lib).