Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ FFMPEG:未定义对“avcodec”寄存器的引用;不链接_C++_Ubuntu_Gcc_Ffmpeg_Linker Errors - Fatal编程技术网

C++ FFMPEG:未定义对“avcodec”寄存器的引用;不链接

C++ FFMPEG:未定义对“avcodec”寄存器的引用;不链接,c++,ubuntu,gcc,ffmpeg,linker-errors,C++,Ubuntu,Gcc,Ffmpeg,Linker Errors,因此,我有一个非常示例代码,用于尝试解码FFMPEG视频流。 我的问题是avcodec不想链接,为此我安装了Ubuntu 13.04。我已根据以下指南从源代码构建ffmpeg: 我只想编译我的文件。请注意,我的ubuntu没有avcodec的任何实现或头文件。我使用的命令行是: gcc-I/home/USER/ffmpeg_build/include-L/home/USER/ffmpeg_build/lib-lavcodec-o test.exe下载/auv/src/dronerosvideo/

因此,我有一个非常示例代码,用于尝试解码FFMPEG视频流。 我的问题是avcodec不想链接,为此我安装了Ubuntu 13.04。我已根据以下指南从源代码构建ffmpeg:

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

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

/tmp/ccKTprFq.o:在函数“fetch”和“decode(int,int,bool)”中:

ar2.cpp:(.text+0x36e): 对“avcodec\u寄存器\u all”的未定义引用

ar2.cpp:(.text+0x378): 未定义对“av\U日志\U设置\U级别”的引用

ar2.cpp:(.text+0x382): 未定义对“avcodec\u find\u decoder”的引用

ar2.cpp:(.text+0x3b1): 未定义对“avcodec\u alloc\u context3”的引用

ar2.cpp:(.text+0x3d6): 对“avcodec_open2”的未定义引用

ar2.cpp:(.text+0x46d): 对“av_init_数据包”的未定义引用

ar2.cpp:(.text+0x50a): 未定义对“avcodec\u decode\u VIDEO 2”的引用

ar2.cpp:(.text+0x534): 对“av_免费_数据包”的未定义引用

/tmp/ccKTprFq.o:(.eh_frame+0x13):未定义对的引用 `__gxx_个性_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++,所以我在代码库的周围有<代码> EXTENT“C”/CODE。


这一点我完全没有任何想法,为什么编译失败?

< P>首先,它是C++,所以你需要使用<代码> G++< /COD>不<代码> GCC < /C> >,这样C++标准库就链接了。这应该去掉
对“\uuuugxx\u personality\uv0”的未定义引用

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

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

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

如果您安装了pkg config,您可以要求它提供正确的CLAG:

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

/usr/bin/ld
是链接器。你的意思可能是:“链接器在
/home/USER/ffmpeg\u build/lib
中找到库。没错!我会修改的。你好!你解决了吗?我也有同样的问题,我陷入了困境。
# 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)