Is it possible in c++ for 2 DLLs including eachother, because each of them uses eachother's classes(Well that's my plan), is this possible or not?
1 Answer
Yes, this is possible. Only you need to compile these dlls as a multi step process. To link a dll, you need a lib file from other dll. This means that you need:
- Create stub implementation of DLL1. This will produce a .lib file for DLL1.
- Link DLL2 with stub .lib pf DLL1.
- Link DLL1 with real .lib of DLL2.
- Relink DLL2 with real lib of DLL1.
Also note that DLLs in general have C interface. You can export classes, but be ready to have set of dlls for each version of used compiler.
3 Comments
Ben Voigt
a note about initialization order (and the reason there are restrictions on what
DllMain does) would be good.Kirill Kobelev
Ben is right. The best design would be when LibMain is not using stuffs from other dll. Or using it in one direction only.
Adam Rosenfield
Depending on exactly what the dependencies are, you might also want to consider breaking up the two DLLs into four with a butterfly dependency diagram:
A.dll and B.dll have no dependencies, and C.dll and D.dll each depend on A and B.