扫描项目中的 "dead" 个函数 / class (Visual Studio)
Scan for "dead" functions in project / class (Visual Studio)
我有一个大项目,有很多死代码(大量未引用的函数)
如何检测 class 中未使用的函数?
P.S.: 该项目使用 C++ space,请不要像这样提供 ReSharper 或 .NET 插件。
15 秒的谷歌搜索给了我这个:
In the build menu select run code analysis on your YourProjectName. In the output window you should see a warning like this for unused sub routines
- 我找到了 Microsoft Visual Studio 2015 Link 的文档。也许链接器可以帮助您解决这个问题(您可以使用 /VERBOSE 选项查看被 /OPT:REF 删除的函数和被 /OPT:ICF 折叠的函数。 ).
Controls the optimizations that LINK performs during a build.
/OPT:{REF | NOREF}
REF | NOREF /OPT:REF eliminates functions and data that are never
referenced; /OPT:NOREF keeps functions and data that are never
referenced. When /OFT:REF is enabled, LINK removes unreferenced
packaged functions and data. An object contains packaged functions and
data (COMDATs) if it was compiled by using the /Gy option. This
optimization is known as transitive COMDAT elimination. By default,
/OPT:REF is enabled in non-debug builds. To override this default and
keep unreferenced COMDATs in the program, specify /OPT:NOREF. You can
use the /INCLUDE option to override the removal of a specific symbol.
When /OPT:REF is enabled either explicitly or by default, a limited
form of /OPT:ICF is enabled that only folds identical functions. If
you want /OPT:REF but not /OPT:ICF, you must specify either
/OPT:REF,NOICF or /OPT:NOICF. If /DEBUG is specified, the default for
/OPT is NOREF, and all functions are preserved in the image. To
override this default and optimize a debugging build, specify
/OPT:REF. Because /OPT:REF implies /OPT:ICF, we recommend that you
also specify /OPT:NOICF to preserve identical functions in debugging
builds. This makes it easier to read stack traces and set breakpoints
in functions that would otherwise be folded together. The /OPT:REF
option disables incremental linking. You have to explicitly mark const
data as a COMDAT; use __declspec(selectany). Specifying /OPT:ICF does
not enable the /OPT:REF option.
- Check this link,也许它也会有所帮助。主要建议是使用外部工具进行静态分析或代码覆盖。
我有一个大项目,有很多死代码(大量未引用的函数)
如何检测 class 中未使用的函数?
P.S.: 该项目使用 C++ space,请不要像这样提供 ReSharper 或 .NET 插件。
15 秒的谷歌搜索给了我这个:
In the build menu select run code analysis on your YourProjectName. In the output window you should see a warning like this for unused sub routines
- 我找到了 Microsoft Visual Studio 2015 Link 的文档。也许链接器可以帮助您解决这个问题(您可以使用 /VERBOSE 选项查看被 /OPT:REF 删除的函数和被 /OPT:ICF 折叠的函数。 ).
Controls the optimizations that LINK performs during a build.
/OPT:{REF | NOREF}
REF | NOREF /OPT:REF eliminates functions and data that are never referenced; /OPT:NOREF keeps functions and data that are never referenced. When /OFT:REF is enabled, LINK removes unreferenced packaged functions and data. An object contains packaged functions and data (COMDATs) if it was compiled by using the /Gy option. This optimization is known as transitive COMDAT elimination. By default, /OPT:REF is enabled in non-debug builds. To override this default and keep unreferenced COMDATs in the program, specify /OPT:NOREF. You can use the /INCLUDE option to override the removal of a specific symbol. When /OPT:REF is enabled either explicitly or by default, a limited form of /OPT:ICF is enabled that only folds identical functions. If you want /OPT:REF but not /OPT:ICF, you must specify either /OPT:REF,NOICF or /OPT:NOICF. If /DEBUG is specified, the default for /OPT is NOREF, and all functions are preserved in the image. To override this default and optimize a debugging build, specify /OPT:REF. Because /OPT:REF implies /OPT:ICF, we recommend that you also specify /OPT:NOICF to preserve identical functions in debugging builds. This makes it easier to read stack traces and set breakpoints in functions that would otherwise be folded together. The /OPT:REF option disables incremental linking. You have to explicitly mark const data as a COMDAT; use __declspec(selectany). Specifying /OPT:ICF does not enable the /OPT:REF option.
- Check this link,也许它也会有所帮助。主要建议是使用外部工具进行静态分析或代码覆盖。