19

As the title says. I have a C++ project, and added 1 C .h file and a C .c source file, but they are having problems because the rest of the project uses a precompiled header, but if I try to include it in those C files, it gives an error. I can't just disable precompiled headers for the whole project, because it's part of a larger project that uses it and has code by somebody else.

So is there a way to select those two C files (the .h header and .c source files) and disable PCH?

Thanks.

3
  • The "precompiled header" feature of Visual Studio is to accelerate building your project. You can safely disable it if you are having problems, but it sounds like there are other problems with your code.
    – BitBank
    Commented Feb 16, 2012 at 21:05
  • Well adding C files has created a problem. But I read that is shouldn't. Only error I'm getting at the moment is with the PCH.
    – bitterman
    Commented Feb 16, 2012 at 21:07
  • If your project doesn't build with precompiled headers disabled, then you have to track down the real problem (e.g. a conflict or bug in your .h or .c files)
    – BitBank
    Commented Feb 16, 2012 at 21:13

2 Answers 2

30

Highlight the file in the Solution Explorer and hit Alt+F7. This will bring up the properties for the file; in the "C/C++" section under "Precompiled Headers" you'll find the relevant options. You don't need to worry about the .h files.

2
  • 3
    Thanks! For me it's Alt/Enter, but nevertheless, this saved me
    – Hack-R
    Commented Mar 2, 2015 at 3:13
  • Honestly it wasn't intuitive that I was changing the options for the file I selected only, but this is great. Thanks a lot for this =)
    – Gaspa79
    Commented Apr 9, 2020 at 11:17
13

In C++ at least, you can right click on the cpp file itself and hit properties -- this lets you override C/C++ compiler settings for that file only. You can use that to disable precompiled headers for that one file.

Not the answer you're looking for? Browse other questions tagged or ask your own question.