21.2. Checking for the Existence of Header Files
Prev | Chapter 21. Multi-Platform Configuration (Autoconf Functionality) | Next

## 21.2. Checking for the Existence of Header Files

Testing the existence of a header file requires knowing what language the header file is. This information is supplied in the `language` keyword parameter to the `CheckHeader` method. Since scons grew up in a world of C/C++ code, a configure context also has a `CheckCHeader` method that specifically checks for the existence of a C header file:

    env = Environment()
    conf = Configure(env)
    if not conf.CheckCHeader('math.h'):
        print('Math.h must be installed!')
        Exit(1)
    if conf.CheckCHeader('foo.h'):
        conf.env.Append(CPPDEFINES='HAS_FOO_H')
    env = conf.Finish()

As shown in the example, depending on the circumstances you can choose to terminate the build if a given header file doesn't exist, or you can modify the construction environment based on the presence or absence of a header file (the same applies to any other check). If there are a many elements to check for, it may be friendlier for the user if you do not terminate on the first failure, but track the problems found until the end and report on all of them, that way the user does not have to iterate multiple times, each time finding one new dependency that needs to be installed.

If you need to check for the existence a C++ header file, use the `CheckCXXHeader` method:

    env = Environment()
    conf = Configure(env)
    if not conf.CheckCXXHeader('vector.h'):
        print('vector.h must be installed!')
        Exit(1)
    env = conf.Finish()

Prev | Up | Next
Chapter 21. Multi-Platform Configuration (Autoconf Functionality) | Home | 21.3. Checking for the Availability of a Function