Thread: Avoid double compile

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    First, in the first makefile change:
    Code:
    precompiled.o: precompiled.h
    to:
    Code:
    precompiled.h.gch: precompiled.h
    and in the 2nd makefile change:
    Code:
    CPPFLAGS        += -O3 -Wall -g -DFOO=BAR
    to:
    Code:
    CPPFLAGS        += -O3 -Wall -g -DFOO=BAR -include precompiled.h
    Next, why are you #including .cpp files?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  2. #2
    Registered User
    Join Date
    Mar 2010
    Posts
    43
    cpp files are included in other cpp files (or h files), inherited project.
    I've made the changes you proposed, but, again, after invoking the main makefile I get reports and warnings I got during compilation of the header file. So, it seems that the .gch file is neglected.
    What is the way to save the job once done?
    Note that for project this large, it would be inappropriate to go through and separate .h files.

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I went through this same problem just a few days ago.
    I assume you read this page: Precompiled Headers - Using the GNU Compiler Collection (GCC)
    Are you sure the .gch file and the rest of your .o files are being compiled with exactly the same compiler flags...?

    Try adding a -H flag to both of them and then you can see exactly which header files are being included for each file. If the .gch file is being used by g++ it will print a ! at the beginning of the line; if it's not used, it'll print an X instead.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by onako View Post
    cpp files are included in other cpp files (or h files), inherited project.
    Don't do that. Compile .cpp files; don't include them.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Elysia View Post
    Don't do that. Compile .cpp files; don't include them.
    Did you miss the part about "inherited project?"

    There are a couple of legitimate reasons that might be done, though most people won't ever run into that.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Travel Expenses-Weird Result
    By taj777 in forum C++ Programming
    Replies: 4
    Last Post: 04-06-2010, 02:23 PM
  2. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  3. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  4. expected primary expression
    By mju4t in forum C Programming
    Replies: 2
    Last Post: 03-27-2007, 06:59 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM