Question:A C++ app has this exe/dll layout:
Main.exe, Framework.dll, PluginA.dll, PluginB.dll, ..., PluginN.dll
Both Main.exe and Framework.dLL provide functions to the Plugin#.dll.
The Plugins are depedent on Main.exe and Framework.dll, but not the other way around. Framework.dll depends on functions provided by Main.exe
Now, the problem is that there is a circular dependency between Main.exe and Framework.dll because Main.exe depends on 1 class in Framework.dll that it uses to manage the lifecycle of Framework.dll
So, in Main.exe, it would be something like this:
Is there a way to still use that one Framework class from Main.exe while still breaking the circular dependency? Specifically, so that Main.exe doesn’t require the export library
Answer:The usual solution to this (although it’s usually used when two libraries have a circular dependency) is to create a ‘dummy’ version of one of them that defines all the relevant entry points but is not in any way dependent on the other and doesn’t need to link against it. That can then be used as a kind of ‘bootstrap’.
So in your case, you might create yourself a
dummy_framework.cppfile that you can build to provide a
maincan then link against. Once you’ve done that, you can compile the ‘real’
frameworkto generate the ‘real’
framework.dlland you should then have a fully functional version of your app. (You can rebuild
mainif you want, but there shouldn’t actually be any need.)
This is all perfectly viable so long as the API of
frameworkis reasonably stable, but even if it isn’t, you’ll get compiler or (more likely) linker errors when you try to build
dummy_frameworkso you can update it then.
If you have better answer, please add a comment about this, thank you!