VincentDM
VincentDM

Reputation: 489

Can I have configurable static linkage in C++?

I know this sounds like "can I have dynamic static linkage" which makes little sense, but let me explain.

I am looking for options to explore and I am aware that there might be something out there that I'm not aware of.

My goal is to have a modular code base where plugins would be provided as static libs, to avoid having exposed dll and result in a single library which clients could swallow in their code.

I imagine having a config file listing all the desired plugins, feed that to a script and boom : a magic sln file with everything ready to be built.

My initial idea is to have a 'main deck' that would know every possible plugin interface and link with them all. Plugins not yet implemented or required by the client would be dead-end/no-op implementations, while required plugins would be implementations realizing the interfaces called by the 'main deck'.

I think that would work, but I find conceptually horrible the idea of linking dead implementations for the sake of modularity.

The main issue I see is at that 'main deck' level : how could I remove useless headers to prevent useless linking or add newly developed ones without editing the code each time? I cannot figure this out without a ton of macros or generating some source files.

Could other patterns solve that issue?

Upvotes: 0

Views: 34

Answers (1)

Bar Stool
Bar Stool

Reputation: 620

I think there is no possible way that doesn't involve macro magic and a complex build system.

If I understand correctly, what you want to do is similar to a library I have used, rocksdb. At build time you can specify what modules/packages you want and it will build them into the static library for you. Check out what they do and see if it is along the lines of what you want.

Upvotes: 1

Related Questions