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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:00:25+00:00 2026-05-12T17:00:25+00:00

I am including a complicated project as a library in C++ using Visual Studio

  • 0

I am including a complicated project as a library in C++ using Visual Studio 2008.

I have a set of include files that are scattered throughout a very complicated directory tree structure. The root of the tree has around ten directories, and then each directory could have multiple subdirectories, subsubdirectories, etc.

I know that all the header files in that structure are necessary, and they are hopelessly interlinked; I can’t just include one directory, because then dependencies in another directory will feel left out and cause the compiler to crash in their annoyance at not being invited to the party. So, everyone has to be included.

I can do this by adding the directories one at a time to the project (right click->properties->additional include directories), but that can be fraught with pain, especially when one of the dependencies has children and makes a brand new subsubsubdirectory.

Is there a way to specify an include directory in a header file itself, so that I can just include that header whenever I need to use the functions it contains? That way, I get an easier way to edit the include files, and I don’t have to make sure that the debug and release versions agree with each other (since the properties right click defaults to the current build, not all builds, a feature that has led to much crashing when switching from debug to release). Even better, is there a way to point to the directory root and force everything to be recursively included?

EDIT for all those replies so far:

I cannot edit the structure of this project. I can only link to it. I don’t like the way the code is organized anymore than anyone else seems to, but I have to work within this constraint. Rather than spending potentially hours in the error-prone process of finding all the interdependencies and putting them in a project file, is there a way to do this programmatically?

  • 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-12T17:00:25+00:00Added an answer on May 12, 2026 at 5:00 pm

    That’s clearly not a good idea, really.

    These directories are a way to organize the code in logical groups.

     /web
       /include
         /web
           /stackoverflow
             /language-agnostic
             /algorithm
             /database
           /meta
             /bug
             /feature-request
       /src
    
     /local/
       /include
         /local
           /my-favorites
       /src
    

    Now if I type

    #include "exception.h"
    

    What the heck am I trying to include ? Where’s that file ? How can I see its content ?

    On the other hand if I type

    #include "local/my-favorites/exception.h"
    

    Then it’s perfectly clear. (and I just have two includes -Iweb/include -Ilocal/include)

    And this way, I can have multiple files that have the exact same name and there would be no ambiguity, nifty when you wish to integrate two different 3rd party libraries which both have such a ‘exception.h’.

    Also note that for clarity, the namespace nesting should reflect the directories organization. So that

    file: "web/include/web/meta/bug/exception.h"
    namespace web { namespace meta { namespace bug {
      struct exception: std::runtime_error {};
    } } } // namespace bug, namespace meta, namespace web
    

    This way it’s easy to think of what header you have to include when you want a class.

    Also note that, for example if you look at boost, they put headers for ‘lazy’ programmers, in each directory, which include the headers of all subdirectories

    file: "web/include/web/meta/bug.h"
    #include "web/meta/bug/file1.h"
    #include "web/meta/bug/file2.h"
    #include "web/meta/bug/file3.h"
    #include "web/meta/bug/file4.h"
    #include "web/meta/bug/file5.h"
    
    file: "web/include/web/meta.h"
    #include "web/meta/bug.h"
    #include "web/meta/feature-request.h"
    

    These includes might also ‘pull’ names into a more generic namespace with a using directive:

    namespace web { namespace meta {
      using ::web::meta::bug::bug;
    } } // namespace meta, namespace web
    

    To make it less painful for developers.

    So as you can see, the language already provide you with a very good way of organizing your code cleanly, if you go with the ‘all includes’ options, you’ll just end up with an unmaintainable mess:

    #include "exception.h"
    #include "bug.h"
    #include "myString.h"
    #include "database_connect.h"
    #include "helper.h" // really love this one...
    #include "file.h" // not bad either eh ?
    

    I’ve had some of these at work… think 20 unqualified includes when you depend on 25+ components… now, do you think that it would be possible to remove a dependency on component X ? 😉

    EDIT: How to deal with 3rd party library ?

    Sometimes a 3rd party library does not live up to your expectations, whether it is:

    • not self-sufficient headers (ie you need to include 3 files to use 1 object)
    • warnings at compilation
    • header organization problem

    you always have the opportunity to wrap them in headers of your own.

    For example, say I have:

    /include
      /file1.h
      /file2.h
      /detail
        /mustInclude.h
        /exception.h
    

    And anytime you wish to include a file, you have to include ‘exception.h’ BEFORE and ‘mustInclude.h’, and of course you have the problem that it is difficult to spot that the files included come from this 3rd party library and not your own (current) project.

    Well, just wrap:

    /include
      /3rdParty
        /file1.h (same name as the one you would like to include, it's easier)
    
    file: "/include/3rdParty/file1.h"
    
    #pragma push
    // ignore warnings caused
    #include "detail/exception.h" // necessary to include it before anything
    #include "file1.h"
    #include "detail/mustInclude.h"
    #pragma pop
    

    And then in your code:

    #include "3rdParty/file1.h"
    

    You have just isolated the problem, and all the difficulty now lies within your wrappers files.

    Note: I just realize that you may have the problem that the 3rd party headers reference each others without taking the ‘relative path’ into account, in this case, you can still avoid the ‘multiple include’ syndroms (even without edition), but that might be ill-fated.

    I suppose you don’t have the opportunity not to use such crap 😡 ?

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

Sidebar

Ask A Question

Stats

  • Questions 196k
  • Answers 196k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can download the final JSR-168 portlet spec from here.… May 12, 2026 at 7:11 pm
  • Editorial Team
    Editorial Team added an answer Let's go from the inside out. (unsigned short*)0 This is… May 12, 2026 at 7:11 pm
  • Editorial Team
    Editorial Team added an answer You can do something along the following lines (I could… May 12, 2026 at 7:11 pm

Related Questions

Concerning headers in a library, I see two options, and I'm not sure if
Before I begin: I have spent a long time on many forums (including Stack
I am looking for a WinForms treeview control with following requirements: Should be not
I have written code that automatically creates CSS sprites based on the IMG tags
In the following snippet, using XmlReader, when I encounter an element. I would like

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.