有没有得到警告有关未使用函数的方法吗? [英] Is there a way to get warned about unused functions?
问题描述
我想找到一个codeBase的未使用的功能 - 包括跨汇编单位。我使用gcc作为我的编译器。
I'd like to find unused functions in a codebase - including across compilations units. I'm using gcc as my compiler.
下面是一个例子:
foo.c的
(假设相应的 foo.h中
)
void foo() {
....
}
void bar() {
....
}
的main.c
:
#include <stdio.h>
#include "foo.h"
int main(void) {
bar();
return 0;
}
在这个例子中,我想获得警告富()
不被使用。
In this example, I'd like to get warned about foo()
not being used.
有是 -Wunused功能
gcc的选项:
-Wunused功能
每当警告静态函数声明,但没有定义或一个非内联static函数未使用。此警告
被-Wall启用。
Warn whenever a static function is declared but not defined or a non-inline static function is unused. This warning is enabled by -Wall.
但它只是静态的功能 - 它不会对上面的例子警告
but it's only for static functions - it won't produce a warning on the example above.
我也会接受的工具/脚本/其他编译器的建议,能为我做到这一点 - 虽然我倒是preFER坚持使用 GCC
如果可能的话
I'll also accept suggestions of tools/scripts/other compilers that can do this for me - though I'd prefer to stick with gcc
if possible.
推荐答案
Caolan麦当劳纳马拉,一LibreOffice的开发商,做了一个小工具来检测在LibreOffice中源$ C $ C这种类型的东西。他们有上千万的功能和安培;方法LibreOffice的使用。他的工具是去除他们的一个关键因素。
Caolan Mc Namara, a LibreOffice developer, has made a small tool to detect this type of thing in LibreOffice source code. They had around thousands functions & methods unused in LibreOffice. His tool is a key element for removing them.
这就是所谓的 callcatcher 。它可以
收集定义的函数/方法和减去名为/引用
collect functions/methods defined and subtract called/referenced
这是直接对汇编输出,因此,它仅适用于x86和x86_64体系。它可以产生输出如这个。您可以使用传统的编译和链接调用gcc的它集成。
It works directly on assembler output and so, it works only for x86 and x86_64 architecture. It can produce output like this. You can integrate it with your traditional compiling and linking call to gcc.
Caolan同意,它应该成为一个gcc的插件。
Caolan agrees that it should become a gcc plugin.
这篇关于有没有得到警告有关未使用函数的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!