This topic is 4388 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I have a project, and when I created it, I created an empty project. Now, I've come to the point when I want to add a precompiled header file to my project. So here's what I did: 1. Add a file called stdafx.h to my project, and copy the contents from another project into it 2. Add a file called stdafx.cpp, and copy contents from another project 3. Edit the properties of my project to create the pch file and compile 4. Edit project properties to use the pch file instead of to create it When I try to compile I get wierd errors:
2>Compiling...
2>stdafx.cpp
2>.\stdafx.cpp(5) : fatal error C1854: cannot overwrite information formed during creation of the precompiled header in object file: 'c:\src\projectname\obj\dbg\client\stdafx.obj'
2>Main.cpp
2>.\Main.cpp(1) : fatal error C1093: API call 'ImportFile' failed '0x80070002' : ErrorMessage: Det går inte att hitta filen.
2>Description: Det går inte att hitta filen.


The errors translated is that the file cannot be found. When I look in the IntDir, one or more .obj files are missing.. Any ideas on how to solve this? I'm using VS2005, and the project is using both managed and unmanaged code. Any ideas on how to fix?

##### Share on other sites
Quote:
 3. Edit the properties of my project to create the pch file and compile4. Edit project properties to use the pch file instead of to create it
If I understand correctly, you're trying the "create PCH" and "use PCH" as two separate stages, one after the other?

If so, the problem is that both should be done together: In the project properties, set "Use Precompiled Header" - and then in stdafx.cpp's file properties, override that setting so it's "Create Precompiled Header" instead. (And remember to #include stdafx.h as the first thing in every source file). Then compile everything once, and it should work correctly, and you don't need to change the project properties again. If you modify stdafx.h, it'll automatically rebuild the PCH data and should continue working like a normal project (just with faster compiling).

##### Share on other sites
Thanks, it worked.. :)

Rating++

##### Share on other sites
BTW, you don't have to name the file "stdafx.h". You can name it anything you want. I name mine "PrecompiledHeaders.h". "afx" is the prefix used by MFC.

##### Share on other sites
Yes, ofcourse.. :) Although, since it's the default name, and I've gotten used to it, I'll just keep calling it stdafx.h.. I'm sure there are some buggy tools out there which I'll be forced to use at some point, that doesn't understand anything else or something like that..

• 16
• 9
• 13
• 41
• 15