在pkg-config搜索路径中未找到cairo软件包。

22

在Mac OS X 1.7.5 / Lion上,我正在尝试使用Homebrew安装cairo软件包。

brew install cairo => PASSED

==> Downloading http://cairographics.org/releases/cairo-1.12.16.tar.xz
Already downloaded: /Library/Caches/Homebrew/cairo-1.12.16.tar.xz
==> ./configure --prefix=/usr/local/Cellar/cairo/1.12.16 --with-x --enable-gobject=yes
==> make install
==> Caveats
This formula is keg-only: so it was not symlinked into /usr/local.

Mac OS X already provides this software in versions before Mountain Lion.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/cairo/lib
    CPPFLAGS: -I/usr/local/opt/cairo/include

==> Summary
  /usr/local/Cellar/cairo/1.12.16: 105 files, 8.0M, built in 2.5 minutes

当我尝试编译我的代码时,我仍然会得到这个错误:

+++ Precompile
Package cairo was not found in the pkg-config search path.
Perhaps you should add the directory containing `cairo.pc'
to the PKG_CONFIG_PATH environment variable
Package 'cairo', required by 'pangocairo', not found

因此,我相应地调整了我的PKG_CONFIG_PATH。

 PKG_CONFIG_PATH=/usr/local/opt/cairo/lib/pkgconfig/:/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig/:

(源 .bash_profile)

尝试重新编译,但是我遇到了完全相同的错误。

验证该文件是否存在于 pkgconfig 目录中... 确实存在。

ls /usr/local/opt/cairo/lib/pkgconfig/ 
cairo-fc.pc           cairo-gobject.pc      cairo-png.pc          cairo-quartz-font.pc  cairo-script.pc       cairo-xcb-shm.pc      cairo-xlib-xrender.pc cairo.pc
cairo-ft.pc           cairo-pdf.pc          cairo-ps.pc           cairo-quartz.pc       cairo-svg.pc          cairo-xcb.pc          cairo-xlib.pc

这里有什么问题?有线索吗?

更新

我的系统中cairo.pc位于两个位置。我已尝试在我的pgg配置路径中使用每个位置,但没有成功。

find /usr -name cairo.pc 
/usr/local/Cellar/cairo/1.12.16/lib/pkgconfig/cairo.pc
/usr/X11/lib/pkgconfig/cairo.pc

pkg-config --variable pc_path pkg-config
/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/pkgconfig
5个回答

14

注意:仅适用于Ubuntu。

解决我的问题很简单。Ubuntu的依赖项只是没有安装好,你可以在这里找到说明:

https://github.com/LearnBoost/node-canvas/wiki

这是对我起作用的方法:

sudo apt-get install libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++

2
当您给出负面评价时,请留下评论说明哪里有问题,这样我们才能改进答案。仅仅进行负面评价对任何人都没有帮助。 - Milimetric
3
apt-get 不适用于 Mac。 - hoangpx
2
对于 Mac 我不确定,但我想要么安装相当于这些库的等效物,要么问题完全不同。 - Milimetric
不是很准确。在Mac中没有这些软件包的直接等价物。 - hithwen

6

ln -s /usr/local/Cellar/cairo/1.12.16/lib/pkgconfig/cairo.pc /usr/local/lib/pkgconfig/cairo.pc

这个命令解决了我的问题。


1
嗨,我的问题与你的类似,只是当我执行你的命令时,它说该文件已存在,而当我尝试构建安装RRDTool(使用cairo)时,在pkgconfig中仍然找不到它。在运行所有你的命令时,是否有一定的顺序?你还做了其他什么可能使我达到期望的结果吗? - AKFourSeven
我在 /usr/local/ 路径下没有 Cellar 文件夹,但已安装 libcairo2。 - Dr.jacky

4
我在Yosemite上遇到了这个问题,通过重新安装cairo解决了它。
$ brew unlink cairo
Unlinking /usr/local/Cellar/cairo/1.14.2... 30 symlinks removed
$ brew install cairo

3

你可以使用PKG_CONFIG_PATH来实现相同的功能。例如:

PKG_CONFIG_PATH=/usr/local/Cellar/cairo/1.12.16/lib/pkgconfig ./configure ....

2

调试和修复此问题的方法:

  1. Run pkg-config --libs cairo . If it says the error below, then the issue still persist.

    Package cairo was not found in the pkg-config search path.
    Perhaps you should add the directory containing `cairo.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'cairo' found
    
  2. To find the default search path used by pkg-config, run:

    pkg-config --list-all --debug 2>&1 > /dev/null |  grep 'Scanning directory'
    

    If you still have error at step (1), the output wouldn't include the directory containing cairo.pc.

  3. Find the directory containing cairo.pc. If you install cairo using brew, usually it's under /opt, in which you can run find /opt -name cairo.pc

  4. Set PKG_CONFIG_PATH env variable with the directory containing cairo.pc. You can do this for one time only:

    PKG_CONFIG_PATH=<path containing cairo.pc> <your command>
    

    like PKG_CONFIG_PATH=<path containing cairo.pc> pkg-config --libs cairo, or export the env

    export PKG_CONFIG_PATH=<path containing cairo.pc>
    

    then run your command.


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