英文:
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: '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.
答案1
得分: 2
这是修复的方法:
- 如果你确实使用brew安装了
ffmpeg
,头文件应该在这里:/opt/homebrew/Cellar/ffmpeg/5.1.2/include/libavcodec/avcodec.h
(库的版本可能不同)。
如果由于某种原因它不在那里,你可以尝试使用find / -name "avcodec.h"
来定位头文件。 - 一旦你确定了
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:
- 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 usingfind / -name "avcodec.h"
- 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="-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 .
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论