Every compilation unit (.cpp / .c file) receives the global defines set by the -D flags in the compiler invocation and those which are themselves included by the compilation unit
The #define DEBUG in main.cpp is not visible outside of the compilation unit.
There’s multiple ways of solving the problem:
creating a dedicated header file like debug_settings.h in which #define DEBUG is present or commented out; then #include <debug_settings.h> in every file in which you need to react on the macros eventually present in that file; This is the most comfortable because it’s solved purely in C++ code without needing help from the build system.
use global build flags to invoke the compiler with the -D DEBUG flag on every compilation unit. See Redirecting...