简体   繁体   中英

C++: How to find out “unused” classes starting from known “point”

I've got a little bit untidy project in C++ (Visual Studio solution + CMakeLists.txt). There is a lot of "includes" from an external projects, and it is hard to say, which one are really in use.

I want to remove all unused headers, and related to them implementation files from both Visual Studio solution and CMakeLists.txt.

Is there any tool for such a task?

A commercial solution for this problem is "Understand for C/C++". It's an application that scans your complete codebase, stores all relations in an internal database, after which you can open all kinds of reports or perform queries on it. I think it has the possibility to also look for unused classes, unused methods, dead code, ...

A free solution might be to use the /VERBOSE linker option of Visual Studio. This option causes the linker to print out all object files that are included in the final executable. You can take this output, match this with all of your .CPP files, and then see which .CPP files are not included in the executable (this might require you to write a small utility, or maybe some Excel magic).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM