Linker Question

I have a large library that contains over 30 separate class definitions. In any given compilation, I want to include a specific subset of these but never will I want to compile and link all of them into the same sketch. This leads me to two specific questions:

Assume my library contains these three classes:

  • alpha.h/alpha.cpp
  • beta.h/beta.cpp
  • gamma.h/gamma.cpp

My test1 sketch wants to include alpha and beta. My test2 sketch needs beta and gamma.

  1. Is there a way I can exclude gamma from test1 compile and alpha from test2?
  2. If all three are included, will gamma be excluded or included into the test1 code. Same question for test2.

I use Visual Studio with Visual Micro and it works pretty well, so an answer that is specific to Visual Studio is fine with me.

The question went well untill the Visual Studio part. NO idea what kind of compiler that uses...

The normal IDE does compile (and I even think link) ALL your libraries. Because you calling #include bla.h has nothing to do with the actual compilation or linking. It just tells your sketch how the, separate compiled, libraries is defined (it's interface). But it's up to the optimizer to only include code that is actually called.

With the exception of virtual methods, the AVR-GCC linker (when used with the Arduino IDE arguments) only includes referenced code in the image.