tags:

views:

155

answers:

3

Is it just to test compile a simple program, with that header file #included in it?

To better understand the compilation process I'm writing my own "configure", which tests for the existence of a few header and library files.

+6  A: 

Yes, use the compiler to compile your simple test program. That's the best and easiest way to see if the compiler can find the header. If you hard code #include search paths you'll always have to modify and adapt for different compilers.

Richard Pennington
Agreed; As Jonathan Leffler notes, this is how Autoconf does it, which is at least a reasonably strong vote of experience in its favor.
Brooks Moses
+2  A: 

The GNU Autoconf suite checks for headers by running test compilations. Just testing for the existence of a file 'filename.h' is fairly simple:

#include <filename.h>
int main(void){return 0;}

You might prefer quotes instead of angle brackets.

Jonathan Leffler
+1  A: 

Using the following program ,you can find the existence of the header file.

#include<stdio.h>
main()
{
        FILE * file;
        if ((file = fopen("/usr/include/stdio.h", "r"))!=NULL)
        {
                fclose(file);
                printf("true");
        }
        perror("err");

}
rekha_sri
Critique? Fixed name for the file you're searching for. Fixed location for the file you're looking for. Using the file you are looking for when compiling the program you are using to look for it. Printing status on stdout when OK and on stderr when not. Not returning different exit statuses for success and failure. Using archaic C definition of main - C99 requires 'int main()' or 'int main(void)', so this must be C89 or older code. Unfortunately, only C99 guarantees a zero exit status from main() when you don't put in an explicit return, so the exit status is undefined.
Jonathan Leffler