【发布时间】:2015-08-14 14:12:11
【问题描述】:
我想使用 frama-c 进行静态 C 代码分析。我已经花了一些精力来正确安装它(希望如此)。这些文件位于C:\CodeAnalysis\frama-c。我想通过 Windows 控制台应用它,例如:
C:\CodeAnalysis\frama-c\bin\frama-c hello.c
hello.c 只是一个简单的 hello-world-program(顺便说一句,我不是 C 程序员,也是编程新手)
#include <stdio.h>
main()
{
printf("Hello World \n");
}
所以当运行上面的命令有如下输出:
[kernel] preprocessing with "gcc -C -E -I. hello.c"
C:/Strawberry/c/x86_64-w64-mingw32/include/stdio.h:141:[kernel] user error: syntax error
[kernel] user error: skipping file "hello.c" that has errors.
[kernel] Frama-C aborted: invalid user input
是的,我已经安装了 Perl,但不知道 Frama 为何使用它。在我看来,stdio.h 似乎有些问题。这可以吗?但是我可以成功编译我的程序。
C:\Strawberry\c\bin\gcc hello.c 生成一个运行良好的 exe 文件。
当从文件中删除include语句时,有如下输出:
[kernel] preprocessing with "gcc -C -E I. hello.c"
hello.c:5:[kernel] warning: Calling undeclared function printf. Old style K&R code?
所以框架本身确实有效,这是我期望的输出。
我也安装了 MinGW 并试图让 Frama 使用它进行编译。所以我删除了 Windows 路径中的草莓条目。之后调用 frama-c 会产生相同的输出。
当完全卸载 Strawberry Perl 时,frama 不起作用(说明 gcc 是一个未知命令),尽管 C:\MinGW\mingw64\bin 也被添加到我的 Windows 路径中,即使是第一个条目。
C:\MinGW\mingw64\bin\gcc hello.c 有效,gcc hello.c 无效。
安装 Perl 后,gcc hello.c 可以工作,即使我从 Windows 路径变量中删除了草莓部分。怎么回事?
我怎样才能让事情正常工作?
【问题讨论】:
-
能否请您详细说明您使用的是哪个版本的 Frama-C?旧版本需要使用
-cpp-extra-args="-I path/to/frama-c/share"之类的东西来启用 Frama-C 自己的 stdlib,否则它将默认为系统的版本,从而导致您观察到的行为。 -
仅供参考,有用于 Windows 的 updated installation instructions 应该允许安装较新的 Frama-C 版本。尽管如此,它们仍需要一些有关命令行工具的知识,而 Frama-C 本身确实需要一些经验才能为用户提供有用的反馈。它确实提供了一些强大的分析,但它不是入门级工具。 C 的新手可能更喜欢其他工具,例如 AddressSanitizer 或 Valgrind。
标签: gcc windows-7-x64 mingw-w64 strawberry-perl frama-c