Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 696013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:01:09+00:00 2026-05-14T03:01:09+00:00

Short story: I can’t make precompiled headers work properly with gcc -c option. Long

  • 0

Short story:

I can’t make precompiled headers work properly with gcc -c option.

Long story:

Folks, I’m using gcc-4.4.1 on Linux and before trying precompiled headers in a really large project I decided to test them on simple program. They “kinda work” but I’m not happy with results and I’m sure there is something wrong about my setup.

First of all, I wrote a simple program(main.cpp) to test if they work at all:

#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/type_traits.hpp>

int main()
{
  return 0;
}

Then I created the precompiled headers file pre.h(in the same directory) as follows:

#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/type_traits.hpp>

…and compiled it:

$ g++ -I. pre.h

(pre.h.gch was created)

After that I measured compile time with and without precompiled headers:

with pch

$ time g++ -I. -include pre.h main.cpp

real    0m0.128s
user    0m0.088s
sys  0m0.048s

without pch

$ time g++ -I. main.cpp 

real    0m0.838s
user    0m0.784s
sys  0m0.056s

So far so good! Almost 7 times faster, that’s impressive! Now let’s try something more realistic. All my sources are built with -c option and for some reason I can’t make pch play nicely with it. You can reproduce this with the following steps below…

I created the test module foo.cpp as follows:

#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/type_traits.hpp>

int whatever()
{
  return 0;
}

Here are the timings of my attempts to build the module foo.cpp with and without pch:

with pch

$ time g++ -I. -include pre.h -c foo.cpp 

real    0m0.357s
user    0m0.348s
sys 0m0.012s

without pch

$ time g++ -I. -c foo.cpp 

real    0m0.330s
user    0m0.292s
sys 0m0.044s

That’s quite strange, looks like there is no speed up at all!(I ran timings for several times). It turned out precompiled headers were not used at all in this case, I checked it with -H option(output of “g++ -I. -include pre.h -c foo.cpp -H” didn’t list pre.h.gch at all).

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:01:09+00:00Added an answer on May 14, 2026 at 3:01 am

    Ok, I think I’ve found the solution: -fpch-preprocess should be used alongside with -c option. It works like a charm!

    Here’s the timings:

    with pch

    $ time g++ -I. -include pre.h -c foo.cpp -fpch-preprocess
    
    real    0m0.028s
    user    0m0.016s
    sys 0m0.016s
    

    without pch

    $ time g++ -I. -c foo.cpp 
    
    real    0m0.330s
    user    0m0.292s
    sys 0m0.044s
    

    Update: I asked the same question on the gcc help mailing list and Ian Lance Taylor explained this strange behavior by my usage of distcc/ccache. These tools first preprocess the source that’s why this options is required.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder if someone can help: Long story short, I'm using MSSQL2005 to build
Long story short, the database I'm using needs to get looked at. Until that
Long story short, how can I disable the screen transitions between activities? We implemented
Long story short, I'm using a buggy WordPress template and we're too far into
To make a short story long, I'm in charge of fixing all these CSS
To make a long story short... I'm building a web app in which the
Long story short, my question is: How can I force GnuPG which private/public key
Long story short, we found files promoting prescription drugs on our server that we
Long story short, I have an ASP.NET application I'm trying to debug and at
Long story short, I'm developing a theme template for a blog that enables you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.