Click here to Skip to main content
Click here to Skip to main content

Using Additional Include Directories

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

Introduction

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.

Background

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.

additional_include_dialog

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.

solution_exp_with_includes

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:

AdditionalIncludeDirectories="D:\COMMON_CODE" 

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

RelativePath="..\..\..\..\COMMON_CODE\C_Log_Writer.h" 

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.

History

  • 4 May 2013: Original post

License

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

Share

About the Author

bkelly13

United States United States
My career began as a navigation electronics technician on submarines in the U.S. Navy. (After a short stint on the battleship USS New Jersey, that was cool.) I worked the next several years as a technician while earning a BSCS in computer science. During my senior year I wrote code for part of a missile flight simulator. That was followed by too many years working with Fortran on the security system at Cape Canaveral Air Force Station. I worked a few years on CLCS (Checkout and Launch Control System for the space shuttle) until it was canceled by NASA, then became the lead antenna engineer for a portable range tracking system. Now I work on telemetry at an Air Force base.
If you work with telemetry please check out this BB: www.irigbb.com. Thank you.

Comments and Discussions

 
SuggestionNot necessary... PinmemberAlbert Holguin8-Jan-14 8:14 
GeneralMy vote of 5 PinmemberVitorHugoGarcia6-May-13 4:54 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.1411022.1 | Last Updated 4 May 2013
Article Copyright 2013 by bkelly13
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid