Search code examples
c++visual-studiosolutionprojects

Shared Code Layout


I have two C++ projects in a solution both of which need to share two common classes. What I want to avoid is having two copies of the source files but I am reluctant to just include the source in one project and reference it in the other.

How is this sort of situation normally handled?


Solution

  • Create a third project, which is either a dynamic or static library (prefer the latter for ease of use) and put the shared code in there. The two other projects #include the headers from the library project and link with library project binary.