Thread: Precompiled header question

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    19

    Precompiled header question

    My code uses large set of libraries that I don't want to be compiled everytime I compile my program, so I want to use a precompiled header to include the libraries. I currently use visual studio 2008 as my IDE. The following is what I have tried so far.

    stdafx.h (precompiled header)
    Code:
    #include <library1.h>
    #include <library2.h>
    .
    .
    .
    #include <libraryN.h>
    MyProg.h
    Code:
    #include "stdafx.h"
    
    class MyProg 
    {
    ...
    }
    MyProg.cpp
    Code:
    #include "stdafx.h"
    #include "MyProg.h"
    
    MyProg::MyProg()
    {
    ...
    }
    .
    .
    .
    client.cpp
    Code:
    #include "stdafx.h""
    #include "MyProg.h"
    
    int main()
    {
       MyProg myProg;
       ...
    }
    The above code compiles fine, but then as soon as I remove #include "stdafx.h" from MyProg.cpp, I get the following compile error.

    1>MyProg.cpp : warning C4627: '#include "MyProg.h"': skipped when looking for precompiled header use
    1> Add directive to 'stdafx.h' or rebuild precompiled header
    1>MyProg.cpp : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

    I want to remove #include "stdafx.h" from the cpp file because I am including MyProg.h already which includes stdafx.h, and I thought that including it again in the cpp file would be redundant. Also, the similar errors occur when I remove the same line from the client.cpp. I tried compiling stdafx.h and then compiling MyProg.cpp, but the error still occured. What is happening? Is there a fault in my logic? Thanks in advance.
    Last edited by donglee; 01-19-2009 at 06:10 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Header File question
    By vishalag in forum C Programming
    Replies: 1
    Last Post: 06-17-2009, 07:25 AM
  2. Header files question
    By Programmer_P in forum C++ Programming
    Replies: 8
    Last Post: 05-14-2009, 01:16 PM
  3. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM
  4. Linux header question
    By invisibleghost in forum Linux Programming
    Replies: 5
    Last Post: 02-17-2005, 10:03 AM
  5. header file question
    By unanimous in forum C Programming
    Replies: 1
    Last Post: 12-15-2001, 08:15 PM