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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:17:18+00:00 2026-06-12T16:17:18+00:00

I recently split some very large files in my c++ project down into many

  • 0

I recently split some very large files in my c++ project down into many smaller files (basically one file per class). This has over doubled the compilation time and also enlarged the resulting executable from 1.6mb to 2.4mb. Why has this made such a huge difference?

Is this a direct result of having to include a few headers in a lot of files as opposed to just a few?

Comiler options:

g++ -Wall -Wextra -g -ggdb -std=c++0x

The executable size I am referring to is after running strip -s executable.

Sizes:

Before with debug symbols: 16MB

After with debug symbols: 26MB

Before without debug symbols: 1.5MB

After without debug symbols: 2.4MB

Additional question:

I’m already using precompiled headers by putting the headers in a pch.hpp and then using the -include pch.hpp option in my g++ flags. Is this the optimal way to do this with gcc? It seems to have very minimal impact on compile times. The only headers currently not being precompiled are apart of the project and subject to change as the project is under heavy development.

  • 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-06-12T16:17:19+00:00Added an answer on June 12, 2026 at 4:17 pm

    There are several reasons why this could happen, here’s a braindump:

    • slower disk access (probably not the cause for such a big increase)
    • multiple translation units including the same headers means those headers are pasted in every one of them. The headers are also pre-processed every time. (most likely cause)
    • static variables or functions defined in headers are duplicated in each translation unit
    • symbols for templates are generated for each translation unit that specialize them

    Here’s some things that can help you out – keep multiple files but reduce compilation time:

    • precompiled headers
    • bulk builds – exclude cpp files from the build but include them in a different implementation file that is compiled.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently took a large, stable XLSM file, and split it apart into an
I recently split some code out into an Android library project. I added references
I recently used the Text Import Wizard to split some text into individual cells,
Recently one of our app servers went down, when it was rebooted the Python
I recently looked into some .NET memory leaks (i.e. unexpected, lingering GC rooted objects)
Recently I had this discussion with some other developers about how too many columns
I recently stumbled across a project that has 27 different CSS files used by
I recently started a project and needed to do some integration with LDAP via
I've recently needed to write a script that performs an os.fork() to split into
My site has just recently run into some issues with High CPU usage from

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.