0
votes

I've been handed the source code for a very large c++ project and asked to make a small change to support some new hardware. I'm not very familiar with c++, as I mostly use C# these days.

When I built the project I'm getting 20+

Error 2 error C1083: Cannot open include file: 'StdAfx.h': No such file or directory D:.. thefile.cpp

From my understanding the "StdAfx.h" is to do with precompiled headers, and is automatically generated?

I followed the answer on this question:

1 Ensure you have the file "stdafx.h" in your project. If you don't (e.g. you removed it) just create a new temporary project and copy the default one from there;

but in doing so noticed that the created stdafx.h file doesn't have the capitalisation of the referenced "StdAfx.h"

I managed to get rid of a single error by copying in the generated file from a new project and changing:

#include "StdAfx.h"

to:

#include "stdafx.h"

I can't help but think this project was using StdAfx.h (there are about 150 references to it) for a reason, and that I shouldn't be adding a bunch of stdafx.h and stdafx.cpp files scattered around the place.

Is there some way of referencing a global stdafx.h file that was being used that could be causing this error?

1
Are you actually intending to use precompiled headers? If not, remove that file, and on your project (if you are using visual studio) unselect "using precompiled headers"Cory Kramer
I am assuming the project used precompiled headers because of the #include. I guess it might be that it wasn't intended to. I'll try compiling without it and see if it works. Edit: I found it was set to "Not Using Precompiled Headers" but the "Precompiled Header File" was set to "StdAfx.h", I'll try removing that field.Joe

1 Answers

0
votes
  1. In Windows, file names are not case-sensitive.
  2. You can't expect that someone else stdafx.h file will be useful in your project. You need to find the original one.
  3. Typically, one project uses one header file for precompiled header, shared by every source file that includes it.