Scrungepipes
Scrungepipes

Reputation: 37590

Unable to specify relative include directory path in MVS 10 for C++

I have a project structure like this, with a couple of header files I'd like to include in a program: \Project\Subdirectory\SourceFile\headerfile1.h \Project\Subdirectory\TestDirectory\headerfile2.h \Project\Subdirectory\TestDirectory\Subdirectory\SourceFile.cpp

SourceFile.cpp has #include "headerfile1.h" and #include "headerfile2.h".

Within MVS, if I select Project/Properties/Configuration Properties/C/C++/General/Additional Include Directories then browse to SourceFile and TestDirectory locations add add the location of headerfile1 and headerfile2 as include paths then everything compiles.

However, the include paths are specified within the project as absolute paths (C:\Users...... etc.) which is not what I want, I want to specify them as relative paths.

I've tried editing these paths, using a millions different combinations in case I'm being daft and getting the levels on indirection off by one, i.e. I've tried all of . .\ ..\ ...\ ....\ .\TestDirectory ..\TestDirectory ...\TestDirectory .\SourceFile ..\SourceFile ...\SourceFile ...\Subdirectory\TestDirectory etc. etc.

Bu nothing works. With anything other than the absolute paths specified the included files can't be located. What am I doing wrong?

Thanks

Upvotes: 0

Views: 4057

Answers (1)

Frank Boyne
Frank Boyne

Reputation: 4570

For #include statements using the quoted form, searching for the file starts with the directory of the file containing the #include statement. In this case that would be the directory \Project\Subdirectory\TestDirectory\Subdirectory containing the file SourceFile.cpp.

To reach headerfile1 from there you need to back up twice to get to '\Project\SubDirectory' and then go down into SourceFile from there. That gives you this...

#include "..\..\SourceFile\headerfile1.h"

To reach headerfile2 you only need to back up once to get to '\Project\SubDirectory\TestDirectory' ...

#include "..\headerfile2.h"

Upvotes: 1

Related Questions