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

The Archive Base Latest Questions

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

Concerning headers in a library, I see two options, and I’m not sure if

  • 0

Concerning headers in a library, I see two options, and I’m not sure if the choice really matters. Say I created a library, lets call it foobar. Please help me choose the most appropriate option:

  1. Have one include in the very root of the library project, lets call it foobar.h, which includes all of the headers in the library, such as "src/some_namespace/SomeClass.h" and so on. Then from outside the library, in the file that I want to use anything to do with the foobar library, just #include <foobar.h>.

  2. Don’t have a main include, and instead include only the headers we need in the places that I am to use them, so I may have a whole bunch of includes in a source file. Since I’m using namespaces sometimes as deep as 3, including the headers seems like a bit of a chore.

I’ve opted for option 1 because of how easy it is to implement. OpenGL and many other libraries seem to do this, so it seemed sensible. However, the standard C++ library can require me to include several headers in any given file, why didn’t they just have one header file? Unless it’s me being and idiot, and they’re separate libraries…

Update:

Further to answers, I think it makes sense to provide both options, correct? I’d be pretty annoyed if I wanted to use a std::string but had to include a mass of header files; that would be silly. On the other hand, I’d be irritated if I had to type a mass of #include lines when I wanted to use most of a library anyway.

Forward headers:

Thanks to all that advised me of forward headers, this has helped me make the header jungle less complicated! 🙂

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

    stl, boost and others who have a lot of header files to include they provide you with independent tools and you can use them independently.

    So if you library is a set of uncoupling tools you have to give a choice to include them as separate parts as well as to include the whole library as the one file.

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

Sidebar

Related Questions

I have a question concerning this code which I want to run on QNX:
I've got a question concerning fields in databases which are measures that might be
I find that most books concerning C++ templates don't tell anything about whether it's
This is a very complicated question concerning how to serialize data via a web
I've been dipping into SitePoint book concerning CSS. The thing that struck me about
Based on a few posts I've read concerning version control, it seems people think
There are some updates with .NET 3.0 concerning how to create and use add-ins
I've seen some very good questions on Stack Overflow concerning delegates, events, and the
Lately I have seen a lot of blog posts concerning how to build loosely
I just finished transferring as much link-structure data concerning wikipedia (English) as I could.

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.