PKG_CHECK_MODULES considered harmful?

后端 未结 2 1575
不知归路
不知归路 2020-11-28 11:13

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

2条回答
  •  孤街浪徒
    2020-11-28 11:49

    There is a blog post here that goes into a bit of detail on the bad side of PKG_CHECK_MODULES:

    http://tirania.org/blog/archive/2012/Oct-20.html

    or this stackoverflow question:

    Using the pkg-config macro PKG_CHECK_MODULES failing

    It essentially boils down to: It causes very unhelpful errors if someone is trying to run autoconf and doesn't have pkg-config installed. Here's an example of an error I got today running autoconf && ./configure:

    ./configure: line 5283: syntax error near unexpected token `FFMPEG,'
    ./configure: line 5283: `   PKG_CHECK_MODULES(FFMPEG, libavutil libavformat libavcodec libswscale, HAVE_FFMPEG=yes)'
    

    To a user/developer just trying to compile a package, this doesn't scream "you need to install pkg-config".

    If (as the article suggests) you just call pkg-config directly, you get more helpful errors, e.g.:

    AC_SUBST(MONO_LIBS)
    AC_SUBST(MONO_CFLAGS)
    if pkg-config --atleast-version=2.10 mono; then
       MONO_CFLAGS=`pkg-config --cflags mono`
       MONO_LIBS=`pkg-config --libs mono`
    else
       AC_MSG_ERROR(Get your mono from www.go-mono.com)
    fi
    

    Edit: in a comment Helmut Grohne says:

    Please don't call pkg-config directly. Doing so breaks cross compilation. Use AC_PATH_TOOL(PKG_CONFIG,pkg-config) or better PKG_PROG_PKG_CONFIG to discover which $PKG_CONFIG to use.

    I would presume this is correct and you should follow his suggestion, but I've not personally tried it.

    Other people suggest not using pkg-config at all; that's a separate issue.

提交回复
热议问题