Questions tagged [stdafx.h]

stdafx.h is a file, generated by Microsoft Visual Studio IDE wizards, that describes both standard system and project specific include files that are used frequently but hardly ever change.

Visual C++ will precompile this file to reduce overall compile times.

The AFX in stdafx.h stands for Application Framework eXtensions. AFX was the original abbreviation for the Microsoft Foundation Classes (MFC).

76 questions
563
votes
5 answers

What is "stdafx.h" used for in Visual Studio?

A file named stdafx.h is automatically generated when I start a project in Visual Studio 2010. I need to make a cross-platform C++ library, so I don't/can't use this header file. What is stdafx.h used for? Is it OK that I just remove this header…
prosseek
  • 182,215
  • 215
  • 566
  • 871
54
votes
10 answers

Handling stdafx.h in cross-platform code

I have a Visual Studio C++ based program that uses pre-compiled headers (stdafx.h). Now we are porting the application to Linux using gcc 4.x. The question is how to handle pre-compiled header in both environments. I've googled but can not come to…
dimba
  • 26,717
  • 34
  • 141
  • 196
47
votes
4 answers

What's with the "Afx" in StdAfx.h?

I'm just curious what Afx stands for. And what about Fx in FxCop?
Qwertie
  • 16,354
  • 20
  • 105
  • 148
39
votes
4 answers

Purpose of stdafx.h

What is the purpose of the file stdafx.h and what is meant by precompiled headers?
ckv
  • 10,539
  • 20
  • 100
  • 144
33
votes
6 answers

stdafx.h: When do I need it?

I see so much code including stdafx.h. Say, I do not want pre-compiled headers. And I will include all the required system headers myself manually. In that case is there any other good reason I should be aware of where I require stdafx.h?
Ashwin Nanjappa
  • 76,204
  • 83
  • 211
  • 292
19
votes
6 answers

Error C1083: Cannot open include file: 'stdafx.h'

When I compiled this program (from C++ Programming Language 4th edition): main.cpp #include #include #include #include "vector.h" using namespace std; double sqrt_sum(vector&); int _tmain(int argc, _TCHAR* argv[]) { …
Kulis
  • 988
  • 3
  • 11
  • 25
15
votes
5 answers

How to use stdafx.h properly?

What is the proper way to use stdafx.h, in terms of separating dependencies? If I put everything in there, then my compiles are blazing fast, and all I need to say in any file is #include "stdafx.h" with the caveats that: I no longer know which…
user541686
  • 205,094
  • 128
  • 528
  • 886
15
votes
2 answers

include stdafx.h in header or source file?

I have a header file called stdafx.h and this one is precompiled of course. I've read that I should include these files into my .cpp files, but some of these statements are already needed in the header file coming with that. Should I add the stdafx…
Marnix
  • 6,384
  • 4
  • 43
  • 78
12
votes
2 answers

Why am I unable to #ifdef stdafx.h?

I am trying to include 2 platform-specific stdafx.h files in my .cpp file, but the compiler is unhappy when I try to #ifdef it. #ifdef _WIN32 #include "stdafx.h" #elif _MAC #include "MAC/stdafx.h" #endif You may wonder why I am using stdafx.h in…
kyue
  • 143
  • 3
  • 8
11
votes
4 answers

Why does stdafx.h work the way it does?

As usual, when my brain's messing with something I can't figure out myself, I come to you guys for help :) This time I've been wondering why stdafx.h works the way it does? To my understanding it does 2 things: Includes standard headers which…
Meeh
  • 473
  • 2
  • 7
  • 13
11
votes
9 answers

Is there a way to use pre-compiled headers in VC++ without requiring stdafx.h?

I've got a bunch of legacy code that I need to write unit tests for. It uses pre-compiled headers everywhere so almost all .cpp files have a dependecy on stdafx.h which is making it difficult to break dependencies in order to write tests. My first…
Ferruccio
  • 98,941
  • 38
  • 226
  • 299
9
votes
3 answers

Why does Visual Studio C++ require including "StdAfx.h" even on files that don't need it?

I understand what precompiled headers are doing with "#include "StdAfx.h" and yes, I know I can turn them off. But that's not my question. If you're using precompiled headers, Visual C++ requires every cpp file to #include "StdAfx.h", even the files…
7
votes
4 answers

Qt5, CMake, AUTOMOC and precompiled headers

How to specify a precompiled header to the output of CMake (2.8.12.1) AUTOMOC ? So far, in the CMakeLists.txt I've tried these two separately: set(AUTOMOC_MOC_OPTIONS "-bstdafx.h") set(AUTOMOC_MOC_OPTIONS "-fstdafx.h") The generated AUTOMOC…
Pencheff
  • 190
  • 1
  • 7
6
votes
5 answers

stdafx.h cross platform without issues?

Hey i've been following learncpp.com tuts for the last couple days, they say to comment out "#include "stdafx.h" from .cpp files for Code::Blocks. Is that a must, to remove the include line? What happens if you had hundreds of files and changed from…
iarp
  • 546
  • 1
  • 9
  • 20
6
votes
12 answers

Intellisense in vs2010 with c++

I can't get intellisense to work. Even if I start with an empty project and add just one file to it with only an include for iostream and an int main() function that prints a char with cout (basically the most basic program), if I try to get…
Baruch
  • 20,590
  • 28
  • 126
  • 201
1
2 3 4 5 6