How to fix .pch file missing on build?

后端 未结 10 1035
日久生厌
日久生厌 2020-11-29 15:18

When I build my c++ solution in Visual Studio it complains that the xxxxx.pch file is missing. Is there a setting I am missing to get the pre-compiled headers back?

相关标签:
10条回答
  • 2020-11-29 15:55

    Fix:

    1. Make sure you have xxxxx.cpp in your project

    2. Compile xxxxx.cpp with /Yc flag (Create Precompiled Header)
      (right click on xxxxx.cpp -> properties -> Precompiled Headers -> create)

    3. Compile all other files with /Yu flag (Use Precompiled Header)
      (right click on project -> properties -> Precompiled Headers -> use)

    0 讨论(0)
  • 2020-11-29 15:58

    I know this topic is very old, but I was dealing with this in VS2015 recently and what helped was to deleted the build folders and re-build it. This may have happen due to trying to close the program or a program halting/freezing VS while building.

    0 讨论(0)
  • 2020-11-29 16:01
    1. Right click to the project and select the property menu item
    2. goto C/C++ -> Precompiled Headers
    3. Select Not Using Precompiled Headers
    0 讨论(0)
  • 2020-11-29 16:03

    NOTE: Later versions of the IDE may use "pch" rather than "stdafx" in the default names for related files. It may be necessary to substitute pch for stdafx in the instructions below. I apologize. It's not my fault.

    1. Right-click on your project in the Solution Explorer.
    2. Click Properties at the bottom of the drop-down menu.
    3. At the top left of the Properties Pages, select All Configurations from the drop-down menu.
    4. Open the C/C++ tree and select Precompiled Headers
    5. Precompiled Header: Select Use (/Yu)
    6. Fill in the Precompiled Header File field. Standard is stdafx.h
    7. Click Okay

    8. If you do not have stdafx.h in your Header Files put it there. Edit it to #include all the headers you want precompiled.

    9. Put a file named stdafx.cpp into your project. Put #include "stdafx.h" at the top of it, and nothing else.
    10. Right-click on stdafx.cpp in Solution Explorer. Select Properties and All configurations again as in step 4 ...
    11. ... but this time select Precompiled Header Create (/Yc). This will only bind to the one file stdafx.cpp.
    12. Put #include "stdafx.h" at the very top of all your source files.

    Lucky 13. Cross your fingers and hit Build.

    0 讨论(0)
  • 2020-11-29 16:04

    In case this is happening to you on a server build (AppCenter) and yo uaer using CocoaPods ensure that your Podfile is checked in.

    AppCenter only runs the "pod install" command if it finds a Pofile and it DOES NOT find the PODS folder on the files.

    I had the folder checked-in, but because git automatically ignores .pch files (check you .gitignore to veryfy this), my .pch weren'nt being checked in.

    I sorted my issue by forcing the .pch files to check it, but Deleting the PODS folder should work too, since Appcenter will run the pod install command in that case.

    Hoppefully this helps somebody.

    0 讨论(0)
  • 2020-11-29 16:05

    Yes it can be eliminated with the /Yc options like others have pointed out but most likely you wouldn't need to touch it to fix it. Why are you getting this error in the first place without changing any settings? You might have 'cleaned' the project and than try to compile a single cpp file. You would get this error in that case because the precompiler header is now missing. Just build the whole project (even if unsuccessful) and than build any single cpp file and you won't get this error.

    0 讨论(0)
提交回复
热议问题