剥离 C++ 库中不需要的应用程序代码 [英] Stripping C++ library of not required code for an application

查看:41
本文介绍了剥离 C++ 库中不需要的应用程序代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个依赖于许多库的应用程序.我正在 ubuntu 机器上从源代码构建所有内容.我想删除应用程序不需要的任何函数/类.有什么工具可以帮助解决这个问题吗?

I have an application dependent on many libraries. I am building everything from sources on an ubuntu machine. I want to remove any function/class that is not required by an application. Is there any tool to help with that?

附言我想从库中删除源代码,而不仅仅是目标文件中的符号.

P.S. I want to remove source code from the library not just symbols from object files.

推荐答案

好的,既然我更了解 OP 的要求,我对此有了另一个答案,我认为这可能更适合他的需求.我认为解决这个问题的方法是使用代码覆盖率工具.毕竟,问题在于确定你可以安全地摆脱它.其实剥离它很容易.

OK, now that I understand the OP's requirements better I have another answer for this that I think might better suit his needs. I think the way to tackle this is with a code coverage tool. After all, the problem is identifying what you can safely get rid of it. Actually stripping it out is easy.

我的 IDE (Visual Studio) 内置了其中一个,但我认为 OP 使用的是 gcc,因此第一个调用端口似乎是 gcov.有许多商业选项,但价格昂贵.此处还有一篇可能有用的帖子.

My IDE (Visual Studio) has one of these built in but I think the OP is using gcc so the first port of call appears to be gcov. There are a number of commercial options, but they are expensive. There's also a potentially useful post here.

当然,您需要的另一件事是一个程序,该程序可以练习您想要保留的库的所有部分,以便为您提供一份覆盖报告,但听起来 OP 已经拥有了.一个好的 IDE 也会有所帮助,因为它可以更轻松地浏览代码.在 Visual Studio 中,我发现跳转到定义和快速简便的书签"是关键功能.

The other thing you need, of course, is a program that exercises all the parts of the library that you want to keep to give you a coverage report to work from, but it sounds like the OP already has that. A good IDE will also help as it makes navigating around the code so much easier. In Visual Studio, I find Jump to Definition and quick and easy 'bookmarking' to be key features.

这篇关于剥离 C++ 库中不需要的应用程序代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆