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 3604484
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:00:13+00:00 2026-05-18T21:00:13+00:00

I use gcc (running as g++ ) and GNU make. I use gcc to

  • 0

I use gcc (running as g++) and GNU make.
I use gcc to precompile a header file precompiled.h, creating precompiled.h.gch; the following line in a Makefile does it:

# MYCCFLAGS is a list of command-line parameters, e.g. -g -O2 -DNDEBUG
precompiled.h.gch: precompiled.h
    g++ $(MYCCFLAGS) -c $< -o $@

All was well until i had to run g++ with different command-line parameters.
In this case, even though precompiled.h.gch exists, it cannot be used, and the compilation will be much slower.
In the gcc documentation i have read that to handle this situation,
i have to make a directory called precompiled.h.gch and put
the precompiled header files there,
one file for each set of g++ command-line parameters.

So now i wonder how i should change my Makefile to tell g++ to create
the gch-files this way.
Maybe i can run g++ just to test whether it can use any existing file
in the precompiled.h.gch directory,
and if not, generate a new precompiled header with a unique file name.

Does gcc have support for doing such a test?

Maybe i can implement what i want in another way?

  • 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-18T21:00:14+00:00Added an answer on May 18, 2026 at 9:00 pm

    It seems weird to answer my own question; anyway, here goes.

    To detect whether a suitable precompiled header file exists, i add a deliberate error to my header file:

    // precompiled.h
    #include <iostream>
    #include <vector>
    ...
    #error Precompiled header file not found
    

    This works because if gcc finds a precompiled header, it will not read the .h file, and will not encounter the error.

    To “compile” such a file, i remove the error first, placing the result in a temporary file:

    grep -v '#error' precompiled.h > precompiled.h.h
    g++ -c -x c++ $(MYCCFLAGS) precompiled.h.h -o MORE_HACKERY
    

    Here MORE_HACKERY is not just a plain file name, but contains some code to make a file with unique name (mktemp). It was omitted for clarity.

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

Sidebar

Related Questions

Running gcc v3.4.6 on the Botan v1.8.8 I get the following compile time error
How would one create a make file for running e.g. xml parser with the
Can I somehow use inline assembly in Haskell (similar to what GCC does for
GCC 4.6.0 Linux cmake 2.8 I am using cmake to generate my make file.
How hard would it be to use GCC instead of VC++ from within Visual
What pointers do you use to compare between compilers? I'm told gcc is the
I'm using Strawberry Perl which includes MinGW's GCC, I'm also making use of the
'''use Jython''' import shutil print dir(shutil) There is no, shutil.move, how does one move
Use case: A does something on his box and gots stuck. He asks B
Use case: 3rd party application wants to programatically monitor a text file being generated

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.