Search code examples
cclangclang-static-analyzer

Clang static analyzer can't find stdio.h


I'm trying to use Clang static analyzer on a very simple program:

#include <stdio.h>
main ()
{
    printf("Hello, world !");
}

When i do

clang helloworld.c

It compiles the program successfully.


When i do

clang -cc1 -analyze -analyzer-checker=unix helloworld.c

it raises an error:

helloworld.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
         ^
1 error generated.

clang --analyze -Xanalyzer -analyzer-checker=unix helloworld.c

doesn't print anything.


What is the problem and how can i fix it? I assume static analyzer doesn't see the header files though the compiler can use them. Please, help me.


Solution

  • Sometimes the checker is not able to read the default include path. So you might want to pass it as an argument. You can find the exact include path clang looks at using this command:

    clang -E -x c - -v < /dev/null
    

    and then your final query will become:

    clang -I<path to include> --analyze -Xanalyzer -analyzer-checker=unix helloworld.c