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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:44:22+00:00 2026-05-25T09:44:22+00:00

According to this answer boost and STL headers belong into the precompiled header file

  • 0

According to this answer boost and STL headers belong into the precompiled header file (stdafx.h in the MSVC world). So I changed the headers of my dynamic link library project and moved all STL/Boost headers into the stdafx.h of my project.

Before

#include <boost/smart_ptr.hpp>

namespace XXX
{
  class CLASS_DECL_BK CExampleClass // CLASS_DECL_BK is just a standard dll import/export macro
  {
    private:
      boost::scoped_ptr<Replica> m_replica;
  }
}

After

namespace XXX
{
  class CLASS_DECL_BK CExampleClass
  {
    private:
      boost::scoped_ptr<Replica> m_replica;
  }
}

Now I have the advantage of decreased compile times, but all the users of my library are getting build errors (e.g. unknown boost::scoped_ptr…) because of the missing includes (which are now moved to my stdafx.h).


What could be a solution for this dilemma?

I want reduced compile times and compile errors after including my headers files are not acceptable for any users of the dll.

Could this help?

  • leave all includes directives as they are but duplicate them in my ‘stdafx.h’? Since the stdafx.h is always included first inside any cpp file of my project I should be fine, and the users won’t get any errors. Or do I loose the speed advantage if multiple includes of the same header occur in one translation unit (got header guards)?

Thanks for any hints!

  • 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-25T09:44:24+00:00Added an answer on May 25, 2026 at 9:44 am

    You should get nearly the same speed increase when you leave the header-includes in place in the library headers and just additionally put them into stdafx.h.

    Alternatively, you could add an additional define (a bulk external include guard)

    // stdafx.h
    #define MY_LIB_STD_HEADERS_ALREADY_INCLUDED
    
    // library_file.h
    #ifndef MY_LIB_STD_HEADERS_ALREADY_INCLUDED
    #include <boost/smart_ptr.hpp>
    ...
    #endif
    

    But I would only do that if you are sure it helps. Just take a stopwatch and run a few re-compilations. (No need to link.) Then you’ll see if there’s any difference.

    Aside

    I’m not sure if adding all boost headers that are needed somewhere in the project is such a good idea. I’d say shared_ptrand friends, boost/foreach, maybe Boost.Format, … are a good idea, but I’d already think twice for the Boost.RegExp headers. Note: I did not do any speed measurements, but I dimly remember a problem with the size of the pch file and some compiler hiccup. I really should do some tests.

    Also check if the Boost Library in question provides forwarding headers and whether you should include them instead. Bloating the precompiled header file can have it’s downsides.

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

Sidebar

Related Questions

According to the answers to this question, I cannot embed a file version in
According to this answer https://stackoverflow.com/questions/551950/what-stackless-programming-languages-are-available/671296#671296 all of these programming languages are stackless Stackless Python
According to this answer: urllib2 read to Unicode I have to get the content-type
According to this stack overflow answer , the _t postfix on type names is
According to this answer , it is better to use the $.ajax() function: $('.showprayer').click(
So I have compiled a python script with py2exe according to this answer .
According to the comment on this answer it is possible to catch Fatal Errors
According this MSDN article HttpApplication .EndRequest can be used to close or dispose of
According to this discussion , the iphone agreement says that it doesn't allow loading
According to this article Silverlight 2 Beta 2 supports the DataContractJsonSerializer object. But, when

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.