致命错误:找不到’libavcodec/avcodec.h’文件,由zergon321/reisen引起。

huangapple go评论73阅读模式
英文:

fatal error: 'libavcodec/avcodec.h' file not found caused by zergon321/reisen

问题

在运行导入"github.com/zergon321/reisen"的Go代码时(重要的是,因为在Linux上安装相关库的方式不同),我遇到了这个问题:

# 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.

我已经使用brew安装了ffmpeg(包括libavcodec/avcodec.h头文件),但它没有被自动识别。

英文:

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: &#39;libavcodec/avcodec.h&#39; file not found
 #include &lt;libavcodec/avcodec.h&gt;
          ^~~~~~~~~~~~~~~~~~~~~~
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.

答案1

得分: 2

这是修复的方法:

  1. 如果你确实使用brew安装了ffmpeg,头文件应该在这里:/opt/homebrew/Cellar/ffmpeg/5.1.2/include/libavcodec/avcodec.h(库的版本可能不同)。
    如果由于某种原因它不在那里,你可以尝试使用find / -name "avcodec.h"来定位头文件。
  2. 一旦你确定了avcodec.h的位置,记下/include目录的完整路径,并在运行你的go代码时传递以下标志:
CGO_CPPFLAGS="-I<path/to/include/directory>" go run <your file name or a period>

对我来说,完整的命令看起来像这样:

CGO_CPPFLAGS="-I/opt/homebrew/Cellar/ffmpeg/5.1.2/include" go run .
英文:

This worked to fix it:

  1. If you indeed installed 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 &quot;avcodec.h&quot;
  2. Once you have established avcodec.h's location, note the full path to the /include directory and run your go code passing the following flag:
CGO_CPPFLAGS=&quot;-I&lt;path/to/include/directory&gt;&quot; go run &lt;your file name or a period&gt;

The full command for me looked like this:

CGO_CPPFLAGS=&quot;-I/opt/homebrew/Cellar/ffmpeg/5.1.2/include&quot; go run .

huangapple
  • 本文由 发表于 2022年10月26日 21:37:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/74208773.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定