Click here to Skip to main content
13,086,120 members (82,209 online)
Click here to Skip to main content
Add your own
alternative version


3 bookmarked
Posted 11 Apr 2011

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 ([^]).

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.


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


About the Author

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

You may also be interested in...

Comments and Discussions

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

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

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

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