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 question concerning a function I created. I would like to show the
It looks like it does not matter what image headers I use for spitting
Beginner question concerning changing the information in a view (and not going to a
I'm trying to make an image similar to one of these: http://www.danasoft.com/vipersig.jpg Not really
Concerning the .htaccess documenation, putting a .htaccess file in a directory should affect this
Concerning data binding I have these classes: public class Foo : List<Bar> { public
concerning Gmail labels - what are they technically speaking. I mean through imap connection
I have a question concerning active record association, referring to this part of the
I have a problem concerning a HashMap in Java. To explain the problem in
I've a question concerning handling touch events for CustomView .I'm adding custom view's dynamically

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.