0

In our projects my team wants to use some C++ source files for different dlls (for example MySource.cpp, amongst others, will be compiled twice to produce both A.dll and B.dll). I'll call this situation "duplicating compilations". I think it is very bad practice and I see mainly 2 reasons:

  • MySource.cpp must be able to support multiple compilers.
  • All dependencies of MySource.cpp must be compiled in A.dll and B.dll.

This imposes a lot of restrictions on the sources which will be compiled multiple times. Is there any other reasons why it shouldn't be done or why it is ok to do it ?

This is how we came to this situation: we first created a module X, and then others modules Y, Z, etc... which are dependent on X. But instead of exporting X's functions to be used in Y, Z, we have duplicated the code of X so that the codes of Y and Z modules all contain a copy of the code of X. Then the code of X has evolved, and now we realize that we need to merge all those codes to have a real dependency. And now we are debating between the above "duct tape" solution and creating an API for X.

Brainless
  • 1,522
  • 1
  • 16
  • 30

1 Answers1

0

My suggestion is to put the functions that are common between A.dll and B.dll into another dll, such as a_b_common.dll.

The DLL functions can call functions in other DLLs.

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
  • Basically this is the API solution I think. I don't see any difference. – Brainless Mar 17 '15 at 16:44
  • This reduces code duplication in `A.dll` and `B.dll`. If the common functions are changed, the `A.dll` and `B.dll` will need to be rebuilt. If the common function are factored out, the `A` and `B` dlls don't need to be rebuilt and will have the save version of common functions. – Thomas Matthews Mar 17 '15 at 17:51
  • However, there is the versioning issue. You may want to keep `A.dll` isolated from `B.dll`, to avoid incompatibility issues when the common functions are upgraded. Welcome to the nightmares of DLLs. – Thomas Matthews Mar 17 '15 at 17:53