使用Mingw64编译cgo程序时出现pkg-config错误

pkg-config errors when compiling cgo program with Mingw64

我正在尝试编译一个在 Mingw64 环境中使用 ffmpeg 的 cgo 程序。我收到来自 pkg-config 的错误,说它找不到 ffmpeg 库:

$ go build -x src/github.com/imkira/go-libav/examples/transcoder.go
WORK=C:\msys64\tmp\go-build616922114
mkdir -p $WORK\b033\
cd c:\users\chris_000\code\go\src\github.com\imkira\go-libav\avfilter
pkg-config --cflags -- libavfilter libavutil
mkdir -p $WORK\b030\
cd c:\users\chris_000\code\go\src\github.com\imkira\go-libav\avcodec
pkg-config --cflags -- libavcodec libavutil
# pkg-config --cflags libavfilter libavutil
Package libavfilter was not found in the pkg-config search path.
Perhaps you should add the directory containing `libavfilter.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libavfilter' found
Package libavutil was not found in the pkg-config search path.
Perhaps you should add the directory containing `libavutil.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libavutil' found
pkg-config: exit status 1

但是当我从 shell 运行 pkg-config 时它工作正常:

$ pkg-config --cflags -- libavfilter libavutil
-I/mingw64/include
$ echo $PKG_CONFIG_PATH
/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig

我正在使用来自 MSYS2 的 Mingw64 环境。我全新安装了 MSYS2(在 Windows 10 上),然后安装了以下软件包:

$ pacman -S pkg-config mingw-w64-x86_64-gcc mingw-w64-x86_64-ffmpeg

我尝试安装的 Go 程序来自 https://github.com/imkira/go-libav examples/transcoder.go。我的 Go 版本是 go1.10.1 windows/amd64.

注意:PKG_CONFIG_PATH 从 shell 导出,libavutil.pclibavcodec.pc 存在于 /mingw64/lib/pkgconfig

pkg-config有两个版本。安装 mingw-w64-x86_64-pkg-config 解决了问题:

pacman -S mingw-w64-x86_64-pkg-config

不知道为什么我已经安装的 pkg-config 版本可以在 shell 上运行,但不能在 cgo 上运行。