Using Automatic Include Path Discovery for Imported Projects

This tutorial shows how to use the VisualGDB include path discovery feature to automatically set missing include paths for imported projects. We will import a basic project that has the following structure:

treeThe source.cpp file has the following contents:

#include <sub.h>
#include <stdio.h>
//#include <add.h>
 
int main()
{
    printf("result = %d\n", subtract(10, 3));
    return 0;
}

It expects the project to be compiled with the following include directories:

  • <project directory>\subdir
  • <project directory>\..\library

Before you begin, install VisualGDB 5.2 or later.

  1. Open Visual Studio and launch any of the VisualGDB Project wizards. We will use the Linux project wizard with the Raspberry Pi toolchain, but the same steps will work with any other VisualGDB project as long as it is using the Clang IntelliSense. 01-prjname
  2. Select “Create a new project -> Application -> MSBuild”. We will not use the “Import project” functionality as it would expect us to have an existing Makefile that can build the project.02-newprj
  3. Select your toolchain and the target machine:03-cross
  4. Press “Finish” to create the project. Then delete the main source file, right-click in Solution Explorer and select “Add->Import folder recursively”:04-import
  5. Enter the path to the “project” folder and click “OK”:prj
  6. If you try to build the project now, Visual Studio will complain that the sub.h file is missing. This happens because the “subdir” directory containing it was never specified as an include search directory:05-missing
  7. Double-click on the error message. VisualGDB will automatically locate the missing header file and display a hint about it:06-suggestNote how IntelliSense starts locating the header file immediately, but the build would still fail.
  8. To fix the build settings automatically, click the “Add to Project Properties” button and then press “Add now”:07-addnow
  9. This will automatically update the project properties for the current configuration and the project will now build successfully:08-builddone
  10. Uncomment the #include <add.h> line. As add.h is located outside the imported project directory, VisualGDB won’t automatically find it and will display it as missing:10-locate
  11. The easiest way to help VisualGDB locate it is to press “Locate” and point to the file on your disk:11-addhIf the same directory contains other missing files, VisualGDB will automatically locate those. If you have many files from different directories missing, you can click “Search in another location” and specify the top folder where VisualGDB should search for them.
  12. Once the file has been located, IntelliSense will begin recognizing it immediately and VisualGDB will give you a chance to review the discovered directories:12-confirm
  13. Click “Add to Project Properties” -> “Add Now” to add the new directory to the build properties and fix the build:13-build

The automatic updating of build settings will work for MSBuild, Make, CMake and QMake projects created by VisualGDB. For imported projects with custom Makefiles VisualGDB can still update IntelliSense, but won’t be able to automatically edit the build system files.