pkg-config无法找到.pc文件,尽管它们在路径中。

13

我在Mac OSX-Lion上使用pkg-config时遇到了一个奇怪的问题。当运行我下载的模块的Python设置时,我收到以下错误:

aspen:python toddysm$ sudo ./setup.py install
Password:
`pkg-config --libs --cflags cld` returns in error: 
Package cld was not found in the pkg-config search path.
Perhaps you should add the directory containing `cld.pc'
to the PKG_CONFIG_PATH environment variable
No package 'cld' found

The `cld` C++ library is absent from this system. Please install it.

然而,在检查/usr/local/lib文件夹时,我发现库和.pc文件都在pkgconfig子文件夹中。

aspen:~ toddysm$ cd /usr/local/lib/
aspen:lib toddysm$ ls -al
total 2640
drwxr-xr-x  6 root  wheel      204 Jul  2 17:38 .
drwxr-xr-x  9 root  wheel      306 Jul  2 15:17 ..
-rwxr-xr-x  1 root  wheel  1339516 Jul  2 17:38 libcld.0.dylib
lrwxr-xr-x  1 root  wheel       14 Jul  2 17:38 libcld.dylib -> libcld.0.dylib
-rwxr-xr-x  1 root  wheel      918 Jul  2 17:38 libcld.la
drwxr-xr-x  3 root  wheel      102 Jul  2 17:38 pkgconfig
aspen:lib toddysm$ cd pkgconfig/
aspen:pkgconfig toddysm$ ls -al
total 8
drwxr-xr-x  3 root  wheel  102 Jul  2 17:38 .
drwxr-xr-x  6 root  wheel  204 Jul  2 17:38 ..
-rw-r--r--  1 root  wheel  279 Jul  2 17:38 cld.pc

在命令行中将PKG_CONFIG_PATH设置为指向/usr/local/lib/并不能帮助解决问题。将其设置到~/.bash_profile中会使pkg-config无法被识别为命令。

我的假设是我缺少某些依赖项,但不确定是什么。当我在Linux上尝试相同的操作时,我缺少Python Dev包python2.7-dev,但我不确定如何在Mac上检查它(是否存在)。

任何帮助都将不胜感激。

4个回答

31

你可以使用以下命令列出 pkg-config 默认搜索的目录:

pkg-config --variable pc_path pkg-config

PKG_CONFIG_PATH 需要将完整的 /usr/local/lib/pkgconfig 路径名添加到变量中。


这是你上面提到的命令的完整输出。看起来 cld.cp 在 pkg_config 路径中被找到,但错误信息有误导性: - toddysm
@Brett Hale,我不知道你可以查询默认值。是的,手册上有所有的内容。谢谢! - Yasushi Shoji

12

需要将环境变量 export 才能在命令中使用。尝试执行:

$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
$ pkg-config --libs --cflags cld

2

看起来,尽管正确设置了PKG_CONFIG_PATH,但Python脚本并没有获取到它。查看脚本,发现它在子进程中启动了pkg-config,我不确定环境变量信息是否传递给了子进程。 不过,通过将库和.cp文件复制到/opt/local/lib/中(这是pkg-config查找的默认文件夹),我解决了这个问题。


1
你可以尝试以下操作:
brew install pkg-config
brew install libvirt

并且对我有效。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接