Domanda

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'.

È stato utile?

Soluzione 2

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

Altri suggerimenti

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

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

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top