Why are project addons compiled even when not used?

Hi,

I see that if I add an addon to the QtCreator project the addon gets compiled, even if I don’t use it (no #include) in any of my .h or .cpp files.

That makes the compilation slower.

In the case of ofxLua, it makes my program crash in ofSetupOpenGL, even if I don’t use the library.

What I would like to understand is why doesn’t the compiler notice that those includes are not needed and skip compilation?

it’s the cpps that are compiled not the .h files so including the .h or not doesn’t make any difference cause the cpps get added to the project compilation phase when you add them to the project.

Thanks. I know that it’s the .cpp that gets compiled, but I assumed that it would only happen if it was referenced somewhere else in the code.

Does that mean that every .cpp in a project and in the addons gets compiled and ends up as part of the binary, even if it’s not used?

One example that comes to mind is ofxPostprocessing, because I use one filter but it compiles ~25 of them. Is it possible to rewrite it in some way so it compiles only what you use?

no, at the end the linker removes any symbol that is not being used but that only happens until everything is compiled

I see. Thanks for the explanation! :slight_smile: