Click here to Skip to main content
13,086,266 members (67,256 online)
Click here to Skip to main content
Add your own
alternative version


3 bookmarked
Posted 4 May 2013

Using Additional Include Directories

, 4 May 2013
Rate this:
Please Sign up or sign in to vote.
Include code from other directories


One of the general goals of most programmers is to re-use code. In order to re-use code, our current project must be able to include it in the build process This programming tip presents a difficulty I found with this option.


When writing my Server and Client TCP/IP applications, the Server and Client code I wrote needed some test projects for development. The core code was several classes that are to be included in other projects. I did not want to put a fresh copy in every project that used them, so they needed to be in a special directory for re-used code. The method of getting access to them in the test project is via the properties. There is a problem with that, hence, this programming tip.

Here is a link to the article and project that prompted this need: My TCP/IP article.

Using the Tip

There are two methods to walk through this tip. First, start your own project. Create a directory somewhere other than within the solution directory to store code that you want to include in multiple solutions / projects.

Second, download the solution from my article I just referenced. Due to the manner that VS (Visual Studio) uses to reference the additional include, you will have to follow these steps to get a good build.

At this point, I presume that you have completed one of the two above operations and have:

  1. a solution ready to build and
  2. a separate directory with code or classes ready to incorporate in the projects of your solution

The operations will be the same for both, so I use my referenced solution as the vehicle to demonstrate this.

Open the solution and right click on a project and select properties. In the "Explorer" section of the Property Pages dialog, select C/C++ as shown in the image below. Note: Other languages may be different.


At the top of the dialog is the field Additional Include Directories. The body of that field has my include directory D:\COMMON_CODE. Replace my entry with the path to your common code directory, then click OK.

If you are using my project, expand the project named Project_Client_ to get the image below. If you are using your own solution and project, you should be able to find the similarities.


In section Header Files, there are six files that are in the additional include directory. They are:

  1. C_Log_Writer.h
  2. C_TCP_Client.h
  3. C_TCP_Constants.h
  4. C_TCP_Format_WSA_Text.h
  5. C_TCP_IADS_Typedefs.h
  6. Gnu_Notice.h

There are not as many in the source files, but you can figure them out.

If a build is attempted now, it will fail because the compiler cannot find these include files and their associated dot CPP files.

Why Not! I cried with frustration! They are exactly where the properties dialog says to find them.

That answer can be found within the file Project_Client.vcproj. (As needed, change the name of your file to match the project but the extension will be the same.) Edit that file and search for the text: Additional to find something like this:


All well and good. Now search for one of the include files and find a line that looks something like this:


There is an entry for each of the files from the include directory. This is the problem. When we type in the absolute path, VS remembers that. When we add a file in using the Add -> Existing Item stuff, VS uses the relative path. After VS implores us to enter the absolute path, it generated a relative path and ignored our entry. That was a bit unfriendly.

To resolve this, close the dot vsproj file and return to the solution explorer. Remove each of the files from the solution, then add them back in. That will update the dot vsproj file. Don't forget that there are two projects in this solution.

That is it. Happy coding.


  • 4 May 2013: Original post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

SuggestionNot necessary... Pin
Albert Holguin8-Jan-14 7:14
memberAlbert Holguin8-Jan-14 7:14 
GeneralMy vote of 5 Pin
VitorHugoGarcia6-May-13 3:54
memberVitorHugoGarcia6-May-13 3:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170813.1 | Last Updated 4 May 2013
Article Copyright 2013 by bkelly13
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid