9

I am trying to use MFC with ProC.
Functions.pc is where I do the ProC syntax to connect to the database. So I include the 'Functions.h' in the dialog model where I want to call the functions in 'Funtions.h'. And now I got this error.

    Add directive to 'stdafx.h' or rebuild precompiled header

I understand that I need to include 'stdafx.h' to 'Functions.h' for it to work. And I did that. It can compile,but then when I try to run the program,it won't recognize the syntax of ProC created by the 'Functions.cpp' created. I don't really understand how to rebuild the precompiled header since I don't understand the codes in 'stdafx.h'.

Mat
  • 202,337
  • 40
  • 393
  • 406
Azuan
  • 878
  • 2
  • 13
  • 33

4 Answers4

14

The common way to use precompiled headers on windows is

  1. Include system , third party headers or infrequently changing headers in stdadx.h
  2. stdafx.cpp usually only includes stdafx.h
  3. All your project cpp files include stdafx.h as the first header
  4. Your project header files should not include stdafx.h

To trigger a precompiled header rebuild,

  1. Modify stdafx.h and do an incremental build
  2. Or Do a rebuild project
parapura rajkumar
  • 24,045
  • 1
  • 55
  • 85
6

Found the solution myself. I need to set the properties of that .cpp file to not using any pre-compiled header.

Azuan
  • 878
  • 2
  • 13
  • 33
  • @Nick It's been a while, can't really remember. But you can just right click on the cpp file and change the setting accordingly. I'm using Visual Studio for this. Click the link for the screenshot http://goo.gl/cKA8mZ – Azuan Sep 15 '14 at 06:29
  • @Nick How to disable precompiled headers for a CPP file: http://stackoverflow.com/a/9319031/1879699 – Andreas Apr 25 '16 at 10:22
3

Within VS 2012 you can set the properties of the Project, the Solution, or Source File(s) to not use Precompiled Headers. See attached graphic for how to do it... VS Turn off Precompiled Headers

Kirk
  • 31
  • 3
0

In VS2017, this error persisted until I switched Project Properties > Configuration Properties > C/C++ > Precompiled Headers > Precompiled Header setting from "Use (/Yu)" to "Create (/Yc)".

For the project setting, use:

  • "Create" for pre-compiled headers to be produced by the project
  • "Use" for pre-compiled headers produced by another project

For per-file settings, use:

  • "Create" for the stdafx.cpp file only
  • "Use" for all other .c and .cpp files
Technophile
  • 464
  • 6
  • 9