在 C/C++ 项目中自动检测库依赖项的最佳方法是什么? [英] What is the best way to auto detect library dependencies in a C/C++ project?

查看:44
本文介绍了在 C/C++ 项目中自动检测库依赖项的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 C/C++ 项目中自动检测库依赖项的最佳方法是什么?

What is the best way to auto detect library dependencies in a C/C++ project?

我有一个项目,我在其中拥有机器上的所有依赖项.它构建并运行.现在我想组装一个 autotools 构建系统.我正在寻找一种好方法来自动检测所需的所有依赖项,例如使用的头文件和链接所需的库.

I have a project where I have all the dependencies on the machine. It builds and runs. Now I want to put together a autotools build system. I am looking for a good way to auto detect all the dependencies needed such as header files used and libraries needed for linking.

图书馆位似乎是我最难弄清楚的.我想能够说,为列表或其他东西中的每个函数生成 AC_CHECK_LIB 命令.我可能可以在 Perl 中做到这一点,但我必须想象它已经存在于其他地方.

The library bit seems to be the hardest for me to figure out. I'd like to be able to say, generate AC_CHECK_LIB commands for every function in a list or something. I could probably do this in Perl, but I've got to imagine it already exists elsewhere.

我所知道的是,我可以使用 objdump 和 nm 查看符号,我可以使用这些实用程序找到函数所属的库,然后我可以在我的 configure.ac 中手动输入 AC_CHECK_LIB 命令来检查它.自动化在这一点上会很棒.

What I know is that I can view symbols with objdump and nm, I can find what library a function belongs to with these utilties, then I can manually enter an AC_CHECK_LIB command in my configure.ac to check for it. Automation would be awesome at this point.

谢谢,陈兹

推荐答案

那种详尽的测试(即每个函数)是不必要的.更不用说维护起来很困难,运行需要一段时间.

That sort of exhaustive testing (i.e., every function) is unnecessary. Not to mention that it would be hard to maintain and take a while to run.

测试您知道需要测试的功能.如果您只是测试某个库是否存在,请选择一个常用的函数以在您的测试中使用.如果您想确保某些功能仅在较新版本中可用,请使用仅在较新版本中提供的功能进行测试.

Test for features that you know warrant a test. If you're just testing for the existence of a library, pick a commonly used function to use in your test. If you want to make sure some feature only in newer vesions is available, test using a function only found in those newer versions.

这篇关于在 C/C++ 项目中自动检测库依赖项的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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