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

  • SEARCH
  • Home
  • 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 4038964
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:32:29+00:00 2026-05-20T12:32:29+00:00

I have one .cpp file that includes a few header files. These header files

  • 0

I have one .cpp file that includes a few header files. These header files may include other header files as well. Include guards are in place to prevent including the same file twice.

Knowing that each file is only included once. Is there a way to figure out the eventual order in which all headers will be included?

I tried gcc -E to get the preprocessor output, but the generated code doesn’t seem usable for extracting the information that I want. Can anyone help?

Edit

The reason why I’m asking is because I need to include my header files in a SWIG interface file in the correct order to avoid generation of weird SWIGTYPE_p_* wrappers.

Update

Thanks for the answers. Using cpp -H seems very useful. However, I can’t find way to grep or sed these results in order to get the simple list of header files in the correct order and without duplicates.

  • 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-20T12:32:29+00:00Added an answer on May 20, 2026 at 12:32 pm

    Use cpp -H. This prints the headers used to standard error. Example:

    $ cpp -H -I../../include base64.cpp 2>&1 >/dev/null | head
    . /usr/include/c++/4.4/cstring
    .. /usr/include/c++/4.4/i486-linux-gnu/bits/c++config.h
    ... /usr/include/c++/4.4/i486-linux-gnu/bits/os_defines.h
    .... /usr/include/features.h
    ..... /usr/include/bits/predefs.h
    ..... /usr/include/sys/cdefs.h
    ...... /usr/include/bits/wordsize.h
    ..... /usr/include/gnu/stubs.h
    ...... /usr/include/bits/wordsize.h
    ...... /usr/include/gnu/stubs-32.h
    

    See the GNU cpp manual for details.

    EDIT Here’s a small Python script that will show the order of inclusion, assuming all headers have include guards:

    import sys
    seen = set()
    for ln in sys.stdin:
        dots, header = ln.rstrip().split(' ', 1)
        if x not in seen:
            seen.add(header)
            print header
    

    (You should be able to translate this to Awk or Perl if Python is not your cup of tea.)

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

Sidebar

Related Questions

I currently have a project with 3 files. One DBheader.h header file that includes:
I have the following code in one cpp file which is part of a
have one time consuming step that flattens a bunch of files. basically i'd like
In my CPP file I have a call that is: pt.x = mDownPoint.x +
I have a very large project with tons of convoluted header files that all
We have few projects, which are compiling my makefile. These make file working fine
I have one class, called A, and it has it's own header file. Then
I've seen fairly consistent advice that an implementation file (.cc / .cpp) should include
I'm working with a large library of files, and have one .cpp to compile.
In MSVC++ #include files are searched for differently depending on whether the file is

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.