I have some C - code where in a cpp-file I include a header-file like that:
#include "../../../c/win/c_pp/include/abc.h"
Now my file abc.h is actually in a folder that should be addressed like this ( with an additional ../ ) :
#include "../../../../c/win/c_pp/include/abc.h"
The strange thing is:
There is no file abc.h in ../../../c/win/c_pp/include/ but VSCode does not complain and compiles fine. I can use either way. Why is that that the case?
CodePudding user response:
There are multiple possibilities:
First:
Your compiler gets additional arguments in the form of -I PATH or /I PATH.
-I .. would add .. to the given include path so transforming
#include "../../../c/win/c_pp/include/abc.h"
to
#include "../../../../c/win/c_pp/include/abc.h"
Therefore correctly accessing the correct file.
Second:
Your seem to use a mingw or similar toolchain on windows. If the correct path of "abc.h" in your filesystem is: "C:\win\c_pp\include\abc.h"
Prefixing this path with ".." (aka parent directory) does not change that.
So "../../../c/win/c_pp/include/abc.h" is the same as "../../../../c/win/c_pp/include/abc.h"
as "/c" or C: has no parent directory.
glaure@Harr MSYS /c
$ cd /c/
glaure@Harr MSYS /c
$ cd ..
glaure@Harr MSYS /
$ cd ..
glaure@Harr MSYS /
$
I hope that helps.
Bye Gunther