1

So let's say I have bunch of header files, currently they are under:

aa/bb/cc/MyHeader1.h
aa/bb/cc/MyHeader2.h
aa/bb/cc/MyHeader3.h

To use these header files, I do:

#include "aa/bb/cc/MyHeader1.h"
#include "aa/bb/cc/MyHeader2.h"
#include "aa/bb/cc/MyHeader2.h"

But in future these header files might be moved to:

xx/yy/zz/MyHeader1.h
xx/yy/zz/MyHeader2.h
xx/yy/zz/MyHeader3.h

Is there a way to not hardcode "aa/bb/cc" portion? Can I define some kind of global macro to be included by the client code so when the header files are moved, I only need to change one place and be done with it? Sth like this(obviously following code doesn't work):

#define LIB_INC "aa/bb/cc"
#include "LIB_INC/MyHeader1.h"

Also, I'd like to avoid using -I at compile time, taking out the aa/bb/cc from the include is not an option to me.

  • Are you using these header files from `aa/bb/cc/`? Or are you trying to make it consistent for the user of these header files, outside of `aa/bb/cc/` entirely? – Justin May 21 '19 at 14:55
  • From inside `aa/bb/cc/`, you can use relative includes with `#include "./MyHeader1.h"`. For the user, publish a consistent `my_lib` prefix, and you can forward includes on. E.g., `my_lib/MyHeader1.h` contains the line `#include `, and you can update the `aa/bb/cc` to `xx/yy/zz`, provided you correctly educate your users that they can only use the `my_lib/*` headers – Justin May 21 '19 at 14:59
  • I am trying to use the header files outside of the aa/bb/cc, and like I said using relative path or no path is not really an option to me because of the way our compiling system are designed. – programmer32 May 21 '19 at 15:07

0 Answers0