[英]libav - undefined reference to 'av_frame_alloc' and more
I am trying to compile this tutorial from the libav doc: link我正在尝试从 libav 文档编译本教程: 链接
I changed nothing on the code!我没有对代码进行任何更改!
But when I compile it with:但是当我编译它时:
gcc test.c -lavformat -lswscale -lavdevice -lavformat -lavcodec -lavutil -lpthread -lm -o example
I get these errors:我收到这些错误:
undefined reference to `check_sample_fmt'
undefined reference to `select_sample_rate'
undefined reference to `select_channel_layout'
undefined reference to `av_frame_alloc'
undefined reference to `av_frame_free'
Searching Dr.google I read that it maybe has something to do with the linking order of the libs.搜索 Dr.google 我读到它可能与库的链接顺序有关。 But I did not found the correct one yet?!但是我还没有找到正确的?!
EDIT: this 'possible dublicate' seems not to be related to my problem编辑:这个“可能重复”似乎与我的问题无关
You probably are running an old code with a newer version of FFmpeg.您可能正在使用较新版本的 FFmpeg 运行旧代码。 Ffmpeg changed some functions names, some create some depreciated warnings while others create errors. Ffmpeg 更改了一些函数名称,一些创建了一些折旧警告,而另一些则创建了错误。
According to the official Ffmpeg github :根据官方的Ffmpeg github :
av_frame_alloc(), av_frame_unref() and av_frame_free() now can and should be
used instead of avcodec_alloc_frame(), avcodec_get_frame_defaults() and avcodec_free_frame() respectively
This doesn't apply in your case, but you get a similar issue if you try to use ffmpeg from C++.这不适用于您的情况,但如果您尝试使用 C++ 中的 ffmpeg,您会遇到类似的问题。
#include <libavcodec/avcodec.h>
int main() {
av_frame_alloc();
}
Unfortunately the ffmpeg headers do not have the proper extern "C" {
wrappers so you have to do it yourself.不幸的是,ffmpeg 标头没有正确的extern "C" {
包装器,所以你必须自己做。
extern "C" {
#include <libavcodec/avcodec.h>
}
int main() {
av_frame_alloc();
}
You are using GNU toolchain.您正在使用 GNU 工具链。 On Windows, I have seen that sometimes MSVC linker also produces.lib files when generating shared/dynamic.dll libraries.在Windows上,我看到有时MSVC linker在生成shared/dynamic.dll库时也会产生.lib文件。 These.lib only holds symbol information needed during linking step but have have no actual machine code. These.lib 仅包含链接步骤中所需的符号信息,但没有实际的机器代码。 As a result, you still have to add them to linker input.因此,您仍然必须将它们添加到 linker 输入。 In Visual studio they can be added to "Project -> properties -> Linker -> Input -> Additional Dependencies" For example: Append the following to the above path "avformat.lib; avcodec.lib; avutil.lib".在Visual Studio中可以将它们添加到“项目 -> 属性 -> Linker -> 输入 -> 附加依赖项” 例如:Append 将以下内容添加到上述路径“avformat.lib; avcodec.lib; avutil.lib”。 This would solve the undefined symbol issue in the question.这将解决问题中未定义的符号问题。 I am not sure how different, things are with GNU.我不确定 GNU 有何不同。 But I hope this can help any Windows user facing a similar problem.但我希望这可以帮助任何面临类似问题的 Windows 用户。 On Windows do these three things:在 Windows 上做这三件事:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.