如何处理 pkg-config 中的替代后端依赖项?

发布于 2024-11-11 15:16:19 字数 805 浏览 3 评论 0原文

我有一个库,分为一个前端和多个后端。客户端程序必须链接前端库和一个后端库。当前端调用 pkg-config 时,我希望 pkg-config 强制指定某些后端。

我们将前端称为 libfoo-frontend,将后端称为 libfoo-backend-alpha 和 libfoo-backend-beta。

一个明显的解决方案似乎是反转依赖关系 - 让每个后端都有“需要:libfoo-frontend”。但是,这不起作用,因为 pkg-config 将在 libfoo-frontend 标志之前给出 libfoo-backend 标志。即,我们最终会得到一个带有“-lfoo-backend-alpha -lfoo-frontend”的链接命令行,并且链接器最终不会包含 libfoo-backend-alpha 因为它不满足任何未满足的依赖关系前面的对象,然后当 libfoo-frontend 中的依赖关系不满足时会失败。

我当前的解决方案是 pkg-config 规范没有指定前端和后端之间的依赖关系。由用户决定链接到前端和某些后端。缺点是用户必须知道这是必需的,如果他们忘记链接到后端,链接就会因未满足的依赖关系而失败,这相对而言信息量不大。

我希望的一个解决方案是让前端规范具有像“Requires: libfoo-backend”这样的行,并且所有后端 pkg-config 规范具有像“Provides: libfoo-backend”这样的行。然后,用户将执行诸如“pkg-config --libs libfoo-frontend libfoo-backend-beta”之类的操作。如果用户忘记指定某些后端,pkg-config 会抱怨并提醒他们。不幸的是,pkg-config 没有这样的“需要”关键字。

I have a library that is split into a front-end and multiple back-ends. Client programs must link against the front-end library, and one back-end library. When pkg-config is called for the front-end, I'd like pkg-config to enforce that some back-end is specified.

Let's call the front-end libfoo-frontend, and the back-ends libfoo-backend-alpha and libfoo-backend-beta.

An obvious solution might seem to be inverting the dependencies- have each back-end have 'Requires: libfoo-frontend'. However, this won't work because pkg-config will then give the libfoo-backend flags before the libfoo-frontend flags. I.e., we'll end up with a link command line with "-lfoo-backend-alpha -lfoo-frontend", and the linker won't end up including libfoo-backend-alpha since it doesn't satisfy any unmet dependencies in the preceding objects, and then will later fail when the dependencies in libfoo-frontend are unmet.

My current solution is that the pkg-config specs do not specify and dependency between the front-end and back-ends. It is up to the user to link against both the front-end and some back-end. The downside is that the user must know that this is required, and if they forget to link against a back-end they'll have the link fail with unmet dependencies, which is relatively uninformative.

A solution that I'd hoped for is to have the front-end spec have a line like 'Requires: libfoo-backend', and all of the backend pkg-config specs have a line like 'Provides: libfoo-backend'. The user would then do something like 'pkg-config --libs libfoo-frontend libfoo-backend-beta'. If the user forgets to specify some backend, pkg-config would complain to remind them. Unfortunately, pkg-config does not have such a 'Requires' key-word.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文