3

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 1

5

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:

  1. Create stub implementation of DLL1. This will produce a .lib file for DLL1.
  2. Link DLL2 with stub .lib pf DLL1.
  3. Link DLL1 with real .lib of DLL2.
  4. 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.

Sign up to request clarification or add additional context in comments.

3 Comments

a note about initialization order (and the reason there are restrictions on what DllMain does) would be good.
Ben is right. The best design would be when LibMain is not using stuffs from other dll. Or using it in one direction only.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.