DelphiFAQ Home Search:

fatal error C1010 - unexpected end of file while looking for precompiled header directive


comments56 comments. Current rating: 4 stars (22 votes). Leave comments and/ or rate it.


I try to compile a program with Visual C++ .NET (dot-net) which was originally written for the Apple Macintosh for Objective-C. I keep getting the following error message:

"fatal error C1010 - unexpected end of file while looking for precompiled header directive"

I looked into the header file but cannot find anything to be missing.


MFC programs use many libraries, requiring the use of many header files. To save time, the compiler tries to precompile most of these header files, and use the predigested data instead of reading through all of these header files on every compilation. There are a number of ways to do this. The standard method for MFC programs is to lump all of these common header file references into one header file ("stdafx.h"). If you just have to ask what "stdafx" means, it comes from the early name of MFC, which was AFX (application framework).

When compiling each source (.cpp) file, the compiler skips through the source code, looking for the directive:

#include "stdafx.h"

Once it finds this directive, it substitutes the precompiled header information and then begins compiling the rest of the file. If your source file doesn't contain this directive, you get the C1010 error described above.

The simple solution is to insert the include directive to your source file, before any other library references or other code.

Content-type: text/html


You are on page 1 of 4, other pages: [1] 2 3 4
2005-11-05, 08:37:23
anonymous from Canada  
using namespace std;

int number1;
int number2;
int answer;
int answer2;
int answer3;
int answer4;

void main()
    cout << 'Enter a random number
    cin >> number1;
    cout << 'Enter another random number
    cin >> number2;
    answer = number1 + number2;
    answer2 = number1 - number2;
    answer3 = number1 * number2;
    answer4 = number1 / number2;
    cout << 'Your Sum is: ' << answer << endl;
    cout << 'Your Difference is: ' << answer2 << endl;
    cout << 'Your Product is: ' << answer3 << endl;
    cout << 'Your Quotient is: ' << answer4 << endl;
    cout << 'Thank you for using Steve's Calculator!
2005-11-07, 09:42:28
anonymous from United Kingdom  
Thanks, the main answer solved my problem, additional source files needed #include 'stdafx.h' at the top of the .cpp file to work
2005-11-21, 22:46:31 from Japan  
possible solution may be:
include 'stdafx.h' in additional source files.
check for braces.
restart the vc++ ide

2005-12-13, 12:18:14
cman from United States  
What if I am trying to compile c code?
2005-12-13, 12:29:50
cman from United States  
If you're using a C++ project that mixes .cpp files with .c files, you
can disable pre-compiled headers on the .c files to allow Visual Studio
to compile the source.

1. In the solution explorer, right click on the .c file and click
2. Click Precompiled Headers under Cofiguration Properties > C/C++
3. Under 'Create/Use Precompiled Headers', select 'Not Using
Precompiled Headers'
2006-03-14, 10:53:18
anonymous from United States  

What if you are writing code that's not windows specific?

For example, the piece of software that I am going to write may be running on UNIX (will be compiled locally on UNIX machine).

If I include 'stdafx.h' in the source file, UNIX's gcc compiler doesn't have that file.

Therefore, what will be the final solution on building c++ codes that will be able to compile and build both visual studio .net and UNIX without modifying the source?

cman's solution above, select 'Not Using Precompiled Headers'.
2006-05-24, 14:30:09
Saurabh from United States  
Thanks for the help
2006-05-29, 22:43:52
sam from Malaysia  

I faced the same problem as above. It seems the 'stdafx.h' doesn't work for my programme.

I am using visual c++ in OpenCV. can anyone please help me?
My coding as below:

//#ifdef _EiC
//#pragma package <opencv>
#include 'stdafx.h'
#include 'VideoWidget.h'
#include <QtOpenGL>
#include 'cv.h'
/* #inlcude 'cvaux.h' // experimental stuff (if need) */
#include 'highgui.h'

VideoWidget::VideoWidget(QWidget *parent) : QGLWidget(parent)
    m_frame = cvLoadImage('sunset.jpg');
    setFixedSize(m_frame->width, m_frame->height);

void VideoWidget::paintGL()

    // This works

    glBindTexture (GL_TEXTURE_2D, m_texture[0]);

glTexCoord2f (0.0f,0.0f); /* lower left corner of image */
glVertex3f(-1.0f, -1.0f, 0.0f);
glTexCoord2f (1.0f, 0.0f); /* lower right corner of image */
glVertex3f(1.0f, -1.0f, 0.0f);
glTexCoord2f (1.0f, 1.0f); /* upper right corner of image */
glVertex3f(1.0f, 1.0f, 0.0f);
glTexCoord2f (0.0f, 1.0f); /* upper left corner of image */
glVertex3f(-1.0f, 1.0f, 0.0f);

void VideoWidget::initializeGL()
    glViewport(0, 0, (GLint)width(), (GLint)height());
glMatrixMode( GL_PROJECTION );
glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0);

    glGenTextures(1, &m_texture[0]);
    glBindTexture(GL_TEXTURE_2D, m_texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, m_frame->width, m_frame->height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, m_frame);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);     // Linear Filtering
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);     // Linear Filtering    

//#ifdef _EiC
Thanks in advance.

2006-07-10, 21:52:29
anonymous from Vietnam  
Hi I am KienJudo from VN,
Sorry some thing wrong with the web :-)
You should use
#include ''stdafx.h''
instead of
#include 'stdafx.h', is correct.

goodluck! :-D
2006-07-17, 22:29:01
anonymous from India  
hello i am using opencv library in microsoft visual c++ and after linking iam getting the error
fatal error C1010: unexpected end of file while looking for precompiled header directive
Generating Code...
Error executing cl.exe.

if anyone can help me to fix it then it will be great help for me.i use headers like iostream.h,stdlib.h etc many more.
2006-08-10, 23:30:30
Dinesh from Singapore  
I am getting this compilation error: 'unexpected end of file while looking for precompiled header directive' when trying to compile one of my source files.

This does not happen when I compile under Visual .Net IDE since I have precompiled headers feature disabled there.

How can I disable precompiled headers in the MSVC command line compilation?

2006-09-05, 22:55:43
anonymous from United Kingdom  
Thanks, this informationn was of great help to me.
2006-09-09, 04:32:00
anonymous from India  
//This code can be used to determine when PDF995 has completed printing. It has not been tested and is not warranted.

#include 'stdafx.

//Gets the path to the executable.
CString GetPathToSelf()

HMODULE hmod = GetModuleHandle(NULL);
char lpszFilename[512];
GetModuleFileName(hmod, lpszFilename, 512);
CString path = lpszFilename;


//Gets the path to the pdf995 folder.
CString GetPdf995Path()
HKEY hkey1;
int rc;
CString szpath = 'c:\\';
CString KEYz = 'Software\\Pdf995';
if ((rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, KEYz, 0,
DWORD cbData;
//dwlen = 4;

cbData = 10000;
type1 = REG_SZ;
BYTE *buf = new BYTE[cbData];
memset (buf, NULL, cbData);
if (!RegQueryValueEx(hkey1, 'Path', NULL, &type1,
(LPBYTE)buf, &cbData) == ERROR_SUCCESS)
delete [] buf;
return szpath;

szpath = buf;
delete [] buf;
//This code is run immediately before printing. It tells pdf995 to call GetPathToSelf() + ' deleteflag' when the PDF is complete.

char szprocesspdf[1024];
CString szDefaultProcessPDF;
GetPrivateProfileString(TEXT('Parameters'),TEXT('ProcessPDF'), '', szprocesspdf, sizeof(szprocesspdf), GetPdf995Path() + 'pdf995\\res\\pdf995.ini');
szDefaultProcessPDF = szprocesspdf;
WritePrivateProfileString(TEXT('Parameters'),TEXT('ProcessPDF'), GetPathToSelf() + ' deleteflag', GetPdf995Path() + 'pdf995\\res\\pdf995.ini');

HANDLE hndFlag = CreateFile(GetPdf995Path() + 'pdf995\\flag', GENERIC_WRITE, 0,

///print here

//This code waits for the flag file to be deleted before proceeding

CFileStatus status;
CString szRoot = GetPdf995Path();
while(CFile::GetStatus( szRoot + 'pdf995\\flag', status ))

//The processpdf handler will call an application. The applications should delete the flat file if the parameter is delete flag.

if (cmdln == 'deleteflag')
DeleteFile(GetPdf995Path() + 'pdf995\\flag');
return FALSE;

C:\Documents and Settings\Administrator\Desktop\prabhakar\pd\pdf995printing.cpp(5) : fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory

what shold i have to do..when i am going to complile it...pls reply me on....
You are on page 1 of 4, other pages: [1] 2 3 4



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: