This is what I’m trying to do:
$ c++ -D GENERATED=build/generated-content main.cpp
My main.cpp file:
#include "GENERATED/header.h"
void f() { /* something */ }
Currently this code fails to compile. How should I fix it? And whether it’s possible at all?
It seems you want to use different headers depending on some “compilation profile”.
Instead of the
-Dsolution, I would rather suggest using the-Idirective to specify the include directories.Given you have the following file tree:
main.cpp:And in your
Makefile(or whatever tool you use), just specify the proper include directory to use, depending on whatever reason you want:Important foot note: I don’t know if you intended to use this as a debug/release switch. However, doing so would be weird: the interface (the included
.hfiles) shouldn’t change betweenreleaseanddebug. If you ever need this, the usual way is to enable/disable some parts of the code using defines, mostly in.c(and.cpp) files.