【发布时间】:2014-09-13 02:50:38
【问题描述】:
我想构建一个静态链接的可执行文件,静态链接到 libavcodec 和 libavformat。 静态 ffmpeg 库是用以下方式构建的:
./configure --enable-static --enable-gpl --enable-nonfree --disable-vaapi
--disable-libopus --prefix=myBuild --disable-swresample
链接器设置如下:
g++ -O2 -static -o myBin myBin-myBin.o someotherlibraries.a
-L/ffmpeg/myBuild/lib -lavformat -lavcodec -lavutil -lrt -lm -lpthread -lz
编译时,我收到 ONLY ONE 错误消息 >:-/
src/ffmpeg/myProgram.cpp:115: error: undefined reference to 'avcodec_alloc_context'
nm /ffmpeg/myBuild/lib/libavcodec.a 的输出 | grep avcodec_alloc_context :
U avcodec_alloc_context3
U avcodec_alloc_context3
000003c0 T avcodec_alloc_context3
U avcodec_alloc_context3
我将 libavcodec.h 包含在 extern "C" {} 中,并且我相信我的静态链接器顺序是正确的。为什么我会收到此错误?是因为这种方法已被弃用吗?我该如何解决这个问题?
解决方案:
不要使用
avCtx = avcodec_alloc_context()
可能来自较旧的代码 sn-ps,但使用
codec = avcodec_find_decoder(CODEC_ID_XYZ);//for completeness but should be the same as before
avCtx = avcodec_alloc_context3(codec)
【问题讨论】:
-
nm /ffmpeg/myBuild/lib/libavcodec.a | grep avcodec_alloc_context的输出是什么? -
我将输出添加到我的帖子中
-
@PaoloBonzini 这能告诉你什么吗?
标签: c++ ffmpeg static-linking libavcodec libavformat