最近在用 Golang 的 gokogiri 做 xpath 解析,github 给的下载提示是这样的。
# Linux
sudo apt-get install libxml2-dev
# Mac
brew install libxml2
go get github.com/moovweb/gokogiri
在 mac 下面这样直接下载,可能会遇到下载失败,提示 libxml2 包没有找到。
# pkg-config --cflags -- libxml-2.0
Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml-2.0' found
pkg-config: exit status 1
# pkg-config --cflags -- libxml-2.0 libxml-2.0
Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml-2.0' found
Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml-2.0' found
pkg-config: exit status 1
PKG_CONFIG_PATH 环境变量中没有配置 已安装的库的 .pc 文件 所在的路径,从而,pkg-config 没有找到已安装的库的 .pc 文件,比如 libavutil 库的 libavutil.pc 文件。于是,不能正确给出结果。
意思就是在 PKG_CONFIG_PATH
中找不到 libxml2,所以这时候需要手动指定路径。
手动指定 PKG_CONFIG_PATH 环境变量
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/libxml2/lib/pkgconfig/
上面的路径是我自己编译 libxml2 的路径,根据自己的实际路径来做。