PKG_CHECK_MODULES 被认为是有害的? [英] PKG_CHECK_MODULES considered harmful?

查看:39
本文介绍了PKG_CHECK_MODULES 被认为是有害的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

各种开发人员不鼓励使用PKG_CHECK_MODULES(例如,在这个答案中)但就我所寻找的而言,没有明确、全面的解释他们的原因.所以,我问:

Various developers discourage the usage of the PKG_CHECK_MODULES (for example, in this answer) but there is no clear, comprehensive explanation of their reasons as far as I've looked for. So, I ask:

  • 为什么 PKG_CHECK_MODULES 会有害?
  • 有哪些替代方案?

我今天第一次使用它.我发现它非常有用,特别是在处理非常复杂的库集时,例如 GTK+,我在其中拥有所有这些依赖项:

I, for one, used it for the first time today. I found it invaluably useful, specially for dealing with pretty intricate library sets, such as GTK+, where I have all these dependencies:

-I/usr/lib/i386-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0
-I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 
-I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 
-I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 
-I/usr/include/freetype2 -I/usr/include/libpng12

-lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 
-lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0
-lgthread-2.0 -lrt -lglib-2.0 

推荐答案

PKG_CHECK_MODULES 的一个重要问题是它会导致不应该发生的故障.如果用户在 /p/a/t/h 中安装 libfoo 并使用 LDFLAGS=-L/p 调用 configure 脚本/a/t/h,用户有理由期待配置找到 libfoo.但是,用户还必须设置 PKG_CONFIG_PATH 以便 configure 脚本可以找到 foo.pc 以便配置成功,并且在我的被打破的意见.如果未通过标准机制找到库,则可以调用 AC_CHECK_LIB 然后仅调用 PKG_CHECK_MODULES 以避免该问题.另一个问题是,PKG_CHECK_MODULES 完全有可能找到信息不准确的 .pc 文件,从而导致构建失败.在这种情况下,需要在PKG_CHECK_MODULES之后调用AC_CHECK_LIB.

One significant problem with PKG_CHECK_MODULES is that it causes failures where it should not. If a user installs libfoo in /p/a/t/h and invokes a configure script with LDFLAGS=-L/p/a/t/h, the user is justified in expecting the configury to find libfoo. But, the user also must set PKG_CONFIG_PATH so that the configure script can find foo.pc in order for the configury to succeed, and in my opinion that is broken. It would be possible to invoke AC_CHECK_LIB and then only invoke PKG_CHECK_MODULES if the library is not found through the standard mechanism to avoid that problem. Another issue is that it is entirely possible for PKG_CHECK_MODULES to find a .pc file in which the information is inaccurate, causing the build to fail. In that case, it is necessary to invoke AC_CHECK_LIB after PKG_CHECK_MODULES.

简而言之,要正确使用PKG_CHECK_MODULES,需要先调用AC_CHECK_LIBS,然后有条件地调用PKG_CHECK_MODULES,再调用AC_CHECK_LIBS 再次验证 PKG_CHECK_MODULES 找到的信息.维护者的所有这些额外工作只是为了让用户更容易在非标准位置安装他们的库是荒谬的.用户应该设置他们的工具链以通过标准机制查找库.

In short, to use PKG_CHECK_MODULES correctly, it is necessary to invoke AC_CHECK_LIBS first, then conditionally invoke PKG_CHECK_MODULES, and then invoke AC_CHECK_LIBS again to validate the information found by PKG_CHECK_MODULES. All of this additional work on the part of the maintainer just to make it easier for users to install their libraries in non-standard location is absurd. The user should set up their tool chain to find libraries through the standard mechanisms.

-- 编辑 --

澄清一下,我并不是建议使用鼓励使用 PKG_CHECK_MODULES 的库的包应避免在其配置中使用它.相反,我建议图书馆不要鼓励使用它并停止分发 .pc 文件..pc 文件试图解决的问题最好在更高的层次上解决.自动工具不是一个包管理系统,这是一个包管理工具应该解决的问题.

To clarify, I am not suggesting that a package which uses a library which encourages the use of PKG_CHECK_MODULES should avoid using it in their configury. Rather, I am recommending that libraries not encourage its use and stop distributing .pc files. The problem that is trying to be solved by .pc files is better addressed at a higher level. The autotools are not a package management system, and this is a problem that should be addressed by a package management tool.

这篇关于PKG_CHECK_MODULES 被认为是有害的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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