0
votes

How to include headers located in project root compiling with GCC C++ compiler?
I want to tell GCC compiler to search for some header files in project root.
I do NOT want to make changes in code and use relative paths in #include directives - e.g. #include "../../myheader.h"
I compile source code I do not own and I do not want to maintain own version.
I do NOT want to specify absolute include path e.g. g++ -c -IC:\root_project_folder .. for obvious reasons.
I have tried: g++ -c -I .., g++ -c -I/ .. and g++ -c -I"/" .. but it does not work.

Please advise.

root_project_folder
|--myheader.h
  |--src_folder
    |-prog.cpp
1
What directory are you in when you issue the g++ command? - rici
If you compile in src_folder then g++ -I.. prog.cc is correct. Live Demo on coliru Otherwise, if you compile in root_project_folder then it is g++ -I. src_folder/prog.cc. Live Demo on coliru In both cases, I would use #include <myheader.h>. (#include with double quotes, I wouldn't use if the header isn't expected in the same dir. like the source.) - Scheff's Cat
Issuing the command I am in the root folder. -I. is the answer I was looking for. Thank you - T. Jastrzębski

1 Answers

0
votes

The symbol for the current directory is ..

You're looking for -I.