gpt4 book ai didi

c++ - FFMPEG:未定义对 `avcodec_register_all' 的引用未链接

转载 作者:搜寻专家 更新时间:2023-10-31 01:43:49 25 4
gpt4 key购买 nike

所以我有一个非常示例代码,用于尝试解码 FFMPEG 视频流。我的问题是 avcodec 不想链接,为此我全新安装了 Ubuntu 13.04。我已经按照此处的指南从源代码构建了 ffmpeg:https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu

我只想编译我的文件。请注意,我的 ubuntu 没有任何 avcodec 的实现或头文件。我使用的命令行是:

gcc -I/home/USER/ffmpeg_build/include -L/home/USER/ffmpeg_build/lib -lavcodec -o test.exe Downloads/auv/src/dronerosvideo/src/ar2.cpp

/tmp/ccKTprFq.o: In function `fetch_and_decode(int, int, bool)':

ar2.cpp:(.text+0x36e):undefined reference to `avcodec_register_all'

ar2.cpp:(.text+0x378):undefined reference to `av_log_set_level'

ar2.cpp:(.text+0x382):undefined reference to `avcodec_find_decoder'

ar2.cpp:(.text+0x3b1):undefined reference to `avcodec_alloc_context3'

ar2.cpp:(.text+0x3d6):undefined reference to `avcodec_open2'

ar2.cpp:(.text+0x46d):undefined reference to `av_init_packet'

ar2.cpp:(.text+0x50a):undefined reference to `avcodec_decode_video2'

ar2.cpp:(.text+0x534):undefined reference to `av_free_packet'

/tmp/ccKTprFq.o:(.eh_frame+0x13): undefined reference to`__gxx_personality_v0'

collect2: error: ld returned 1 exit status

如果我删除 -L 参数,编译器会说:

/usr/bin/ld: cannot find -lavcodec

这意味着链接器在 /home/USER/ffmpeg_build/lib 中找到了库。此外,如果我们检查库的实现,它是否存在:

nm ffmpeg_build/lib/libavcodec.a | grep "register_all"
0000000000000000 T avcodec_register_all

另外,因为它是 C++,所以我在库的 include 周围有 exten "C"

此时我完全没有任何想法,为什么编译会失败?

最佳答案

首先,它是 C++,因此您需要使用 g++ 而不是 gcc 以便链接 C++ 标准库。这应该摆脱 undefined reference to '__gxx_personality_v0'

然后,要链接的库的顺序实际上很重要。您需要在使用它的对象(或源或其他库)之后指定一个库。

将它们放在一起,像这样的命令行可以工作(在我的测试中):

g++ -o test.exe -I$HOME/ffmpeg/include test.cc -L$HOME/ffmpeg/lib -lavcodec

(实际上,根据 ffmpeg 的构建方式,您可能还需要其他库,例如 pthreads 或 libx264)

如果您安装了 pkg-config,可能只要求它提供适当的 clags:

# Since you didn't install ffmpeg to a known location, tell pkg-config about that location.
export PKG_CONFIG_PATH=$HOME/ffmpeg/lib/pkgconfig
g++ -o test.exe $(pkg-config -clags libavcodec) test.cc $(pkg-config -libs libavcodec)

关于c++ - FFMPEG:未定义对 `avcodec_register_all' 的引用未链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24487203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com