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:
printf("result = %d\n", subtract(10, 3));
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.
- 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.
- 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.
- Select your toolchain and the target machine:
- Press “Finish” to create the project. Then delete the main source file, right-click in Solution Explorer and select “Add->Import folder recursively”:
- Enter the path to the “project” folder and click “OK”:
- 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:
- Double-click on the error message. VisualGDB will automatically locate the missing header file and display a hint about it:Note how IntelliSense starts locating the header file immediately, but the build would still fail.
- To fix the build settings automatically, click the “Add to Project Properties” button and then press “Add now”:
- This will automatically update the project properties for the current configuration and the project will now build successfully:
- 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:
- The easiest way to help VisualGDB locate it is to press “Locate” and point to the file on your disk:If 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.
- Once the file has been located, IntelliSense will begin recognizing it immediately and VisualGDB will give you a chance to review the discovered directories:
- Click “Add to Project Properties” -> “Add Now” to add the new directory to the build properties and fix the 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.