开发者

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 tri开发者_运维知识库ed 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


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"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜