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 -D
solution, I would rather suggest using the -I
directive to specify the include directories.
Given you have the following file tree:
/
debug/
header.h
release/
header.h
main.cpp
:
#include "header.h"
/* some instructions, not relevant here */
And in your Makefile
(or whatever tool you use), just specify the proper include directory to use, depending on whatever reason you want:
g++ -I debug main.cpp // Debug mode
g++ -I release main.cpp // Release mode
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 .h
files) shouldn't change between release
and debug
. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With