在 C/C++ 中自动检测库依赖关系的最佳方法是什么?项目?
在 C/C++ 项目中自动检测库依赖关系的最佳方法是什么?
我有一个项目,其中包含机器上的所有依赖项。它构建并运行。现在我想组装一个自动工具构建系统。我正在寻找一种好方法来自动检测所需的所有依赖项,例如使用的头文件和链接所需的库。
图书馆似乎是我最难弄清楚的。我希望能够为列表或其他内容中的每个函数生成 AC_CHECK_LIB 命令。我也许可以在 Perl 中做到这一点,但我必须想象它已经存在于其他地方。
我所知道的是,我可以使用 objdump 和 nm 查看符号,我可以使用这些实用程序找到函数属于哪个库,然后我可以在configure.ac 中手动输入 AC_CHECK_LIB 命令来检查它。在这一点上,自动化会很棒。
谢谢, 陈兹
What is the best way to auto detect library dependencies in a C/C++ project?
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.
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.
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.
Thanks,
Chenz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这种详尽的测试(即每个功能)是不必要的。更不用说它很难维护并且需要一段时间才能运行。
测试您知道值得测试的功能。如果您只是测试库是否存在,请选择一个常用函数在测试中使用。如果您想确保某些功能仅在较新版本中可用,请使用仅在这些较新版本中找到的功能进行测试。
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.
我现在也面临着类似的挑战。 autoconf 对于 C++ 技巧来说确实不太方便,但它有基本的砖块来构建顶部的功能。看了这里和那里后我的建议:
AC_CHECK_LIB
和AX_CXX_CHECK_LIB
。是的,您需要编写一个小型测试程序,但这允许您测试类型、类(sizeof
可能有效,但构造函数呢?)、内联函数(您不能这样做)在链接器的帮助下)和外部函数(你不能用nm
来做到这一点)。来自
aclocal.m4
:现在在
configure.ac
中:I had a similar challenge now. autoconf is really not so handy for C++ tricks, but it has basic bricks to build the functionality on the top. My suggestions after looking here and there:
AC_CHECK_LIB
andAX_CXX_CHECK_LIB
. Yes, you need to write a mini-test-program, but this allows you to test types, classes (sizeof
might work, but what about constructors?), inline functions (this you can't do with help of linker) and external functions (you can't do it withnm
).From
aclocal.m4
:Now in
configure.ac
:在 Windows 上,我使用 Dependency Walker 来完成类似的事情。它的输出很详细,但通常会显示可执行文件所需的每个库。
我不知道 Linux 或 Mac 上有类似的东西,但我确信一定有东西存在。
On Windows I've used Dependency Walker for stuff like that. Its output is verbose, but it will generally show you every library that is required by the executable.
I don't know of anything like that for linux or mac, but I'm sure something has to exist.