I have some relative path in my *.vcxproj
<ItemGroup>
<ClCompile Include="myFile.cpp" />
<ClCompile Include="..\..\Some\Reference\file.cpp" />
<ClCompile Include="..\..\Some\Other.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\SomeOther\Headers.h" />
...
</ItemGroup>
When I compile this, it always complaints as follows for both files
fatal error C1083: Cannot open include file: ‘StdAfx.h’: No such file or directory
fatal error C1083: Cannot open include file: ‘StdAfx.h’: No such file or directory
When i copy these files manually to directory containing myFile.cpp, update proj file for path, it compiles.
So Any clue why does this happen? and How to fix it?
Probably because there is no file named “StdAfx.h” in ..\..\Some\Reference. When you #include “StdAfx.h”, the first place it looks is in the current directory; then, it checks all the directories configured in the include path.
Further, I bet you DO have a StdAfx.h in the same directory as myFile.cpp. When you move those CPP files to the directory containing myFile.cpp, then when it checks for StdAfx.h in the current directory, it succeeds and includes it. That’s why moving the file fixes the problem.
If you want to make it work with the files in ..\..\Some\Reference, then you need to add myFile.cpp’s directory to the include paths (in your project settings).