fatal error C1852:is not a valid precompiled header file - c++

I have seen all the articles on web, but nothing seems to resolve my issue.
Someone plz help me out on this.
I am using debug mode, VS 2010, .net 4 Framework.
In project properties,
CLR is on in general
CLR in on in C++->general
All .cpp files are having use (/yu) in precompiled hearder settings
stdafx.cpp has /yc (create) with clr on

I had the some problem.
Validate that all the C++ files properties (right click on the file in the solution explorer and Properties) are mark with "Common Language RunTime Support" as "/clr"

This error occurs when another version of the compiler has created the PCH file or the PCH is corrupt. Try cleaning the solution or simply rebuilding.

Related

VS Always looks for precompiled headers

I am Using VS Community 2015 to create C++ Console applications
I am trying to stop using pre-compiled headers.
I have deleted #include "stdafx.h" , and the stdafx .h and cpp files.
In the project properties pages I selected
Not Using Precompiled Headers
I tried clean, rebuild, nothing works.
VS keeps looking for the precompiled headers:
1>ConsoleApplication2.cpp(7): fatal error C1010: unexpected end of
file while looking for precompiled header. Did you forget to add
'#include "stdafx.h"' to your source?
Anyone have a solution?
VS project properties can be overridden on individual source file level. Inspect the properties of ConsoleApplication2.cpp (and other source files where you get errors) and make sure their PCH-related properties are not bolded, i.e. that they are in the state "inherit from parent or project defaults."
Also make sure that you are editing properties for the configuration (e.g. "Debug") which you are actually building. The VS property dialog allows you to edit properties for any configuration, not just the one currently selected in the solution-wide configuration combo. What I usually do is to always set the dialog's configuration to the "Active" option before exiting it, so that when I open it, I don't have to check.

visual studio not seeing my include files

This may be a very simple question but I haven't been able to figure it out so any help is appreciated.
I have a header that is located in a general folder because I want to use it in several projects for example:
C:\user\geninclude\program\header.h
I created a new empty project with a very simple main, in the main I put
#include <program/header.h>
I then went to the project properties and in VC++ in include directories added C:\user\geninclude\
but when I tried to build the program the program tells me it cannot find header.h because is not in the current directory or in the build system path.
I also tried in the project properties in C/C++ general Additional Include Directories adding C:\user\geninclude\ but still the same error.
I know is something simple I am missing, but I don't know what, I am very new to this just learning.
For reference I am using Visual Studio 2013.
Thank you in advance for your help.
UPDATE: Thank you all for your kind responses, I have tried everything you have told me (check release vs debug in both instances, change / for \ and <> for "", and double checking the header and still the system does not see it. It really is very weird. I'll keep trying...
Please check if your file is really an header file otherwise it won't appear on include.
What you can also do (as a workaround if you need that method fast) is to put your header file (or folder with header files) on the visual studio "include" folder. The path should look like this "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include"
PS: You should also check the properties configuration when you're adding the path to VC++ include directories. You could be adding the path to debug configuration and trying to run it in release mode.
You do indeed want
Project Properties -> Configuration Properties -> C/C++ -> Additional Include Directories
(or something close to that; I'm using VS 2008). Make sure the configuration you're editing in the top left (debug/release) matches the configuration you're building with (typically visible up top in the main window). So it sounds like you may have done it correctly; I'd double-check for the file's existence in that location. You could also try program\header.h instead of program/header.h. If none of those work, try adding C:\user\geninclude\program to the include directories (no \ at the end) and change it to #include "header.h". If that doesn't work either, you've almost surely got the header file in the wrong spot.
Another thing that can cause include files not being picked up is a difference between the platform set in your c++ project's Property Pages and your "Active Solution Platform" in configuration manager. Can just check if one is set to x64 and the other x86
check if you have specified the path correctly. for example I had written cpp instead of c++ and therefore suffered a lot and wasted like an hour searching here and there.
For Visual Studio 2019 users:
Project(P) > yours_project_name properties(P) > Platform Toolset Visual Studio 2019(V###)
Reasoning: You might download the project from Online and they used other version of Visual Studio as Platform.
Project(P) > yours_project_name properties(P) > Windows SDK Version ##.#(latest installed version).
Reasoning: You might download the project from Online and they used version SDK 8.0 while you have SDK 10.0
ntucvhw

C++ Precompiled Header Disabled

In Visual Studio 2015, I have a C++/CLI project with the following error:
"fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?"
I turned off precompiled headers in the project options but it keeps giving me the same error. I even removed the name of the precompiled header file but it still says "stdafx.h".
Edit:
Yes, every source file indivuduially doesn't have it enabled.
Ok. Hans Passant found out what was happening:
The build configuration that I used to build it still had precompiled headers enabled.
You may have disabled it for the project, but each individual source file can have it's own specific compiler settings. It's also possible you disabled pre-compiled headers for a specific source file, erroneously mistaking that action for a project wide setting.
For each individual C/C++ file in Solution Explorer, right click on it and select "Properties". Under C/C++ -> Precompiled Headers, make sure the Precompiled Header setting is "Not using Precompiled Headers".
The right click on your Project name in Solution Explorer and select "Properties as well" Double-check that the project settings are the same.
And if there's a stdafx.cpp file, it likely has the "Create Precompiled Header" setting. You can typically remove this file if it doesn't have any relevant code in it.
Repeat all the same steps for each Solutions configuration (e.g. both Debug and Release).
I met the same problem (turned off precompiled in project properties but the error remains).
Solution:
open .proj file with any text editor and search for
<PrecompiledHeader>Use</PrecompiledHeader>
you will see that there are still some properties set to use it. Just replace word "Use" with "NotUsing" and problem fixed.
Microsoft Visual Studio 2015:
Right click on solution -> Configuration Properties -> C/C++ -> Precompiled Headers -> Precompiled Header => Not Using Precompiled Headers
In my case, I found the pch.h still set in: c++ -> advanced -> forced include files.
Anyhow, Andrew's solution is still the best. Just open the proj. file in a text editor and ctrl-f search for the filename causing the issue. Much easier than skimming through all the properties in vs.

Build Eclipse C++ Docfrac project using Visual Studio 2012

Can someone please help me understand how to build the open source Docfrac C++ Eclipse project with Visual Studio 2012?
Docfrac
UPDATE 1:
When building project in VS 2012, I get:
Unexpected end of file while looking for precompiled header. Did you forget to add '#include "pch.h"' to your source?
UPDATE 2: Got past above issues thanks to Rowland.
Now i get, could not open #include vcl.h. No such file or directory.
CLOSING COMMENTS:
Unfortunately, what I wanted to achieve is not directly possible. Thanks to Rowland for pointing me in the right direction.
For the error relating to precompiled headers, select the source code files (.cpp or .c) that you added to the project in the Solution Explorer. Then right-click, choose Properties. Then in the C/C++ section under Precompiled Headers, select the option that says "Not using precompiled headers". Rebuild and bingo.
Alternatively, you can right-click the project itself and set it for all files.

What is the difference between "Create Precompiled Header" (/Yc) and "Use Precompiled Header" (/Yu) in Visual Studio?

I read the documentation in MSDN, but in the end I didn't get a clear idea what is the practical difference between them, exactly. Both seem to require stdafx.h to be added at the top of every *.cpp file.
I'm using VS2008.
Can anyone help clear things up?
Short summary of how to use PCH files in Visual Studio:
All cpp files in the project have to include stdafx.h (you can change this to something else if you wish)
Select project in Solution Explorer and in Properties -> C++ -> Precompiled Headers set 'Create/Use precompiled headers' to 'Use'. Hit Apply
While the Property Pages are still shown select stdafx.cpp in solution explorer and set the value to 'Create'
Well, I think that you must first understand the purpose of precompiled headers. In large projects, it can take ages to process all the headers required by a single client extension for example, so some people prefer to distribute the .pch files along with their libraries. In order to generate the .pch files, you use the /Yc compiler flag and the person who wants to consume your library will set the /Yu flag. See here and here for details.