# Scanner Discovery

## General

Scanner Discovery (sometimes called Autodiscovery) is a method of finding include paths and predefined preprocessor macros which the compiler uses during compilation of the code.

Even a simplest C/C++ program just printing "Hello World" needs to include system headers. Consider:

    #include <stdio.h>
    #include <stdlib.h>

    int main(void) {
      puts("!!!Hello World!!!");
      return EXIT_SUCCESS;
    }

Indexer needs to be able to find headers stdio.h and stdlib.h and parse them to provide accurate index. In this example, the headers define prototype of function puts and macro EXIT_SUCCESS.

CDT will try to discover include paths and preprocessor symbols automatically for supported toolchains. There are 2 main ways to discover those:

1. Built-in Settings. CDT will try to detect built-in compiler symbols and include paths running the compiler with special options and parse the output of this special run. Most compilers provide such an option to print built-in include paths and symbols. Built-in settings are implied and do not get passed to compiler during regular compilation.
2. Build Output Parser (BOP). Another method that CDT employs is to analyze build output of the regular build with Build Output Parser. Often, include paths are supplied to the compiler with -I options, and macros with -D options and BOP will try to find those in the output. That method relies on verbose build output of your build where all these options are actually printed by make.

CDT uses Language Settings Providers to discover the settings (starting with version CDT 8.1). Typically Language settings Providers are specialized. One will provide built-in compiler settings and another one settings detected by Build output Parser. There is also an extension point defined in CDT to allow third party Eclipse plugins to contribute custom Language Settings Providers.

The setting entries found by Scanner Discovery can be inspected in project properties on "Preprocessor Include Paths, Macros etc." page. Each Language Settings Provider can be expanded to show the entries it discovered.

If information retrieved by auto-discovery is insufficient or the project deviates from a standard one supported by CDT a user can enter additional include paths and macros manually under "User Settings Entries".

## Project Explorer View

The Project Explorer View provides a means to view some of the settings. The discovered include paths are shown under the project when "Includes" node is expanded.
Also, a "Wrench" overlay icon is shown for those file/folders where distinct entries are discovered which differ from those of parent folder. Wrench is not shown on project level.
In the example below, Hello.cpp was compiled with added -DHELLO compiler option. After BOP discovery "Wrench" overlay is shown for this file.

## Console View

The output of built-in compiler specs detectors can be inspected to troubleshoot problems running the command. To do so, enable checkbox "Allocate console in the Console View".

When checkbox "Allocate console in the Console View" is enabled, output of each run of the provider will be directed to a special console in the Console View.

C/C++ Indexer

Setting up include paths and macros for C/C++ indexer

C/C++ Preferences: Scanner Discovery
C/C++ Project properties: Preprocessor Include Paths, Macros, etc.