简体   繁体   English

如何通过设置 MYLIB_LIBS 和 MYLIB_CFLAGS 来“覆盖 pkg-config”?

[英]How to "override pkg-config" by setting MYLIB_LIBS and MYLIB_CFLAGS?

I'm trying to build some program which uses GNU autotools on a Unix-like OS.我正在尝试构建一些在类 Unix 操作系统上使用 GNU 自动工具的程序。 It needs some library which my OS distribution doesn't have, say mylib , so I download, build and install that library under /opt/mylib .它需要一些我的操作系统发行版没有的库,比如mylib ,所以我在/opt/mylib下下载、构建和安装该库。

Now, I want to tell the configure script to use mylib under /opt/mylib , but it doesn't have a command-line option such as --mylib-location= .现在,我想告诉配置脚本在/opt/mylib mylib下使用mylib ,但它没有命令行选项,例如--mylib-location= However, configure --help tells me:但是, configure --help告诉我:

Some influential environment variables:
... snip ...
  MYLIB_CFLAGS C compiler flags for mylib, overriding pkg-config
  MYLIB_LIBS   linker flags for mylib, overriding pkg-config
... snip ...

I'm guessing these are shell variables I need to set.我猜这些是我需要设置的 shell 变量。 But - what exactly do I need to set them to?但是 - 我究竟需要将它们设置为什么?

These variables are expanded in the command-line for compilation and for linking respectively.这些变量在命令行中分别展开用于编译和链接。 So, typically, the _CFLAGS would need to indicate an include file search path and _LIBS would need to tell the linker to use the library, plus indicate a search path for it.因此,通常情况下, _CFLAGS需要指示包含文件搜索路径,而_LIBS需要告诉链接器使用该库,并指出它的搜索路径。

In your specific case, and assuming typical layout of /opt/mylibs , you need to set:在您的特定情况下,并假设/opt/mylibs典型布局,您需要设置:

MYLIB_CFLAGS=-I/opt/mylib/include
MYLIB_LIBS="-L/opt/mylib/lib -lmylib"

and that should do it.那应该这样做。 The text about "overriding pkg-config" is due to how pkg-config is used as the default for obtaining these flags.关于“覆盖 pkg-config”的文本是由于pkg-config是如何用作获取这些标志的默认值的。 Example (for the PNG library and on my system):示例(对于 PNG 库和我的系统):

# pkg-config --cflags libpng
-I/usr/include/libpng16
# pkg-config --libs libpng
-lpng16 -lz

pkg-config has search paths configured for include and library directories, plus a repository of .pc files etc., with which it determines the system location of various libraries/packages. pkg-config 具有为包含和库目录配置的搜索路径,以及.pc文件等的存储库,它确定各种库/包的系统位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM