makefile

Meaning of -DHAVE_CONFIG_H in makefiles


I am starting to learn about makefiles. Looking at the output I see a lot of occurrences of:

g++ -DHAVE_CONFIG_H -I ...

what is -DHAVE_CONFIG_H exactly? What is the function of this compilation option?


Solution

  • All that -DHAVE_CONFIG_H does is to define the pre-processor token HAVE_CONFIG_H exactly as if you had #define HAVE_CONFIG_H right at the start of each of your source files.

    As to what it's used for, that depends entirely upon the rest of your source file (and everything that it includes as well). That's where you should be looking for to work out its effect.

    It looks like it may mean that a header file config.h is available and should be included, in which case you'll probably find the following sequence somewhere in you source files:

    #ifdef HAVE_CONFIG_H
        #include "config.h"
    #endif
    

    which will include the header file when you say it's available. However that's supposition on my part and by no means the exact effect, just what I would use such a preprocessor symbol for.