Search code examples
mingwmingw-w64cgomsys2

pkg-config errors when compiling cgo program with Mingw64


I'm trying to compile a cgo program that uses ffmpeg in a Mingw64 environment. I'm getting errors from pkg-config saying it can't find the ffmpeg libraries:

$ 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

But when I run pkg-config from the shell it works fine:

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

I am using the Mingw64 environment from MSYS2. I did a clean install of MSYS2 (on Windows 10) then installed the following packages:

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

The Go program I am trying to install is examples/transcoder.go from https://github.com/imkira/go-libav. My Go version is go1.10.1 windows/amd64.

NB: PKG_CONFIG_PATH is exported from the shell, and libavutil.pc and libavcodec.pc are present in /mingw64/lib/pkgconfig.


Solution

  • There are two versions of pkg-config. Installing mingw-w64-x86_64-pkg-config fixed the issue:

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

    No idea why the version of pkg-config I had already installed worked from the shell but not from cgo.