Here's what I'm doing when including header files across multiple directories in C / C ++.
root
|-dir1
|-main1.c
|-dir2
|-main2.c
|-dir3
|- config.h
Now if you want to include config.h in both main1.c
and main2.c
, in two files
#include "../dir3/config.h"
I think I will write
../dir3/
Is a little annoying to write.
Therefore, create the following header file.
config_sub.h
#include "../dir3/config.h"
Then place it as follows.
root
|-dir1
|-main1.c
|-config_sub.h
|-dir2
|-main2.c
|-config_sub.h
|-dir3
|- config.h
By doing this, in main1.c
and main2.c
#include "config_sub.h"
By doing config.h
You can include the contents of.
If you don't want to create the file manually, you may be able to handle it by writing a script in Python ...
Recommended Posts