我正在尝试在一个非常简单的程序上使用 Clang 静态分析器:
#include <stdio.h>
main ()
{
printf("Hello, world !");
}
当我做
clang helloworld.c
它成功地编译了程序。
当我做
clang -cc1 -analyze -analyzer-checker=unix helloworld.c
它引发了一个错误:
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
不打印任何东西。
有什么问题,我该如何解决?
我假设静态分析器看不到头文件,尽管编译器可以使用它们。
请帮我。
最佳答案
有时检查器无法读取默认的包含路径。所以你可能想把它作为参数传递。
您可以使用以下命令找到 clang 查看的确切包含路径:
clang -E -x c - -v < /dev/null
然后您的最终查询将变为:
clang -I<path to include> --analyze -Xanalyzer -analyzer-checker=unix helloworld.c
关于Clang 静态分析器找不到 stdio.h,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37674464/