Click here to Skip to main content
Click here to Skip to main content
Go to top

Including stdafx.h in a non-default location

, 11 Apr 2011
Rate this:
Please Sign up or sign in to vote.
The vc compiler and intellisense don't look for pre-compiled header in a similar manner, this is a summary of the issue along with workarounds
The vc compiler automatically disambiguates the location of stdafx.h when you #include "stdafx.h", using a set of defined rules (see MSDN for specifics), BUT IntelliSense does not. Therefore even when a piece of code compiles successfully, IntelliSense will not work correctly because it doesn't use the same logic as the compiler. If you specify the exact location of the file, as in #include "..\\stdafx.h", IntelliSense will now work right, but the compiler will call an error since it's looking for #include "stdafx.h" and not any other variant (bad string compare logic).
 
What makes this worse? Microsoft claims this is by design (http://connect.microsoft.com/VisualStudio/feedback/details/533605/stdafx-h-cant-be-parsed-with-intellisense-squiggles-mechanism[^]).
 
There are a couple of ways to get around this "feature". Do a double include since the header guard should prevent problems:
#include "stdafx.h"      //Pre-compiled header for compiler
#include "..\\stdafx.h"  //Exact location of pre-compiled header for intellisense
 
Or include the location of stdafx.h as one of the project's default directories. A less preferable method in my case since I'm developing the code to eventually transfer to a larger project.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Albert Holguin
Engineer
United States United States
I'm an angry monkey. Big Grin | :-D

Comments and Discussions

 
QuestionPossible fix Pinmemberrobindegen20-Aug-12 22:48 
GeneralRe: ...and it is true that you can specify the file name, in you... PinmemberAlbert Holguin19-Apr-11 12:15 
GeneralRe: sorry but i'm not about to download a zip file from the inte... PinmemberAlbert Holguin19-Apr-11 12:12 
GeneralRe: Unfortunately, successful compilation does not imply well-fo... PinmemberVyacheslav Lanovets19-Apr-11 11:27 
Generalno comment PinmemberRedDK22-Jul-11 7:00 
GeneralThe problem is that this is not a valid C++ program. There i... PinmemberXentrax19-Apr-11 3:35 
GeneralRe: Since this was moved and posted as a comment, I'll answer ag... PinmemberAlbert Holguin19-Apr-11 3:43 
Generalincorrect pch file handling Pinmemberjustinh19-Apr-11 8:40 
GeneralRe: incorrect pch file handling PinmemberAlbert Holguin19-Apr-11 9:58 
GeneralAlternatives PinmentorHans Dietrich11-Apr-11 16:07 
GeneralRe: Alternatives PinmemberAlbert Holguin11-Apr-11 16:12 
AnswerRe: Alternatives PinmentorHans Dietrich11-Apr-11 23:03 
GeneralRe: Alternatives PinmemberAlbert Holguin12-Apr-11 4:00 
GeneralRe: Alternatives PinmemberAlbert Holguin12-Apr-11 4:06 
GeneralRe: Alternatives PinmemberAnna-Jayne Metcalfe18-Apr-11 21:44 
GeneralRe: Alternatives PinmemberAlbert Holguin19-Apr-11 3:47 
GeneralRe: Alternatives PinmemberAnna-Jayne Metcalfe19-Apr-11 4:22 
QuestionRe: Alternatives PinmemberAlbert Holguin19-Apr-11 4:32 
AnswerRe: Alternatives PinmemberAnna-Jayne Metcalfe19-Apr-11 4:44 
GeneralRe: Alternatives PinmemberAlbert Holguin19-Apr-11 5:02 
GeneralRe: Alternatives PinmemberAnna-Jayne Metcalfe19-Apr-11 10:53 
GeneralRe: Alternatives PinmemberAlbert Holguin19-Apr-11 11:20 
GeneralRe: Alternatives PinmemberAnna-Jayne Metcalfe19-Apr-11 21:42 
GeneralRe: Alternatives PinmemberAlbert Holguin20-Apr-11 2:08 
GeneralRe: Alternatives PinmemberAnna-Jayne Metcalfe20-Apr-11 2:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140922.1 | Last Updated 11 Apr 2011
Article Copyright 2011 by Albert Holguin
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid