When running Go code on Mac M2 (important, because installation of related libs work differently on Linux) that imports "github.com/zergon321/reisen" I got this:
# github.com/zergon321/reisen
/Users/ido/go/pkg/mod/github.com/zergon321/reisen@v0.1.4/audio.go:4:11: fatal error: 'libavcodec/avcodec.h' file not found
#include <libavcodec/avcodec.h>
^~~~~~~~~~~~~~~~~~~~~~
1 error generated.
I have ffmpeg (includes the libavcodec/avcodec.h header) installed using brew
brew install ffmpeg
but it doesn't get picked up by itself.
This worked to fix it:
ffmpeg
with brew, the header file should be there -> /opt/homebrew/Cellar/ffmpeg/5.1.2/include/libavcodec/avcodec.h
(lib version could be different).
If it is not there for some reason, you can try to locate the header file using find / -name "avcodec.h"
avcodec.h
's location, note the full path to the /include
directory and run your go code passing the following flag:CGO_CPPFLAGS="-I<path/to/include/directory>" go run <your file name or a period>
The full command for me looked like this:
CGO_CPPFLAGS="-I/opt/homebrew/Cellar/ffmpeg/5.1.2/include" go run .