简体   繁体   中英

E1696 cannot open source file “stdafx.h” during compilation

I have two projects A and B. In project A, I have created a source file called Logger.cpp where I have #include "stdafx.h" in the includes part. The stdafx.h is present in the project A. In project A's properties, I have project B's header file locations in the 'Additional include directories' property. When I am trying to compile the solution in Visual Studio 2013 , it gets compiled successfully, but when I try to migrate my solution to Visual Studio 2019 and compile the whole solution, or only project A, I am getting the error E1696 cannot open source file "stdafx.h" .

What I have tried:

  1. I have copied the stdafx.h file from project A to project B which results in conflicts and does not allow me to open any header file included in the stdafx.h file.
  2. I have deleted project A completely and then created a new C++ project as stdafx.h file gets created when a new project gets created.

Both the above approach does not resolve the issue.

Am I missing something here?

According to Microsoft Docs , when you create a new project in Visual Studio, a precompiled header file named pch.h is added to the project. (In Visual Studio 2017 and earlier, the file was called stdafx.h.)

So, you could set stdafx.h in Properties->C/C++->Precompiled Header->Precompiled Header file .

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM