开发者

Best way to programatically check for existence of header file?

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.


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.


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.


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");

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜