FFMPEG:未定义的对“avcodec_register_all”的引用没有链接

时间:2014-06-30 09:42:11

标签: c++ ubuntu gcc ffmpeg linker-errors

所以我有一个非常示例的代码,用于尝试解码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:在函数`fetch_and_decode(int,int,bool)'中:

     

ar2.cpp :(文本+ 0x36e):    未定义的引用`avcodec_register_all'

     。

ar2.cpp :(文本+的0x378):   未定义的引用`av_log_set_level'

     。

ar2.cpp :(文本+ 0x382):   未定义的引用`avcodec_find_decoder'

     。

ar2.cpp :(文本+ 0x3b1):   未定义的引用`avcodec_alloc_context3'

     。

ar2.cpp :(文本+ 0x3d6):   未定义的引用`avcodec_open2'

     。

ar2.cpp :(文本+ 0x46d):   未定义的引用`av_init_packet'

     

ar2.cpp :(文本+ 0x50a):   未定义的引用`avcodec_decode_video2'

     。

ar2.cpp :(文本+ 0x534):   未定义的引用`av_free_packet'

     

/tmp/ccKTprFq.o :(。eh_frame + 0x13):未定义的引用   `__gxx_personality_v0'

     

collect2:错误:ld返回1退出状态

如果我删除-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 ++,我有exten "C"围绕库的包含。

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

1 个答案:

答案 0 :(得分:3)

首先,它是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)