我想构建静态链接到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
编译时,我只收到一条错误消息>: - /
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
我包含带有extern"C"{}的libavcodec.h,我相信我的静态链接器顺序是正确的.为什么我会收到此错误?是因为这个方法已被弃用了吗?我怎么解决这个问题?
解:
不要用
avCtx = avcodec_alloc_context()
从可能较旧的代码片段,但使用
codec = avcodec_find_decoder(CODEC_ID_XYZ);//for completeness but should be the same as before avCtx = avcodec_alloc_context3(codec)
Non-maskable.. 6
您是否尝试过调用avcodec_alloc_context3?
我遇到没有问题调用avcodec_alloc_context3,分配extradata然后调用avcodec_open2.
链接顺序也应该是-lavutil -lavformat -lavcodec
您是否尝试过调用avcodec_alloc_context3?
我遇到没有问题调用avcodec_alloc_context3,分配extradata然后调用avcodec_open2.
链接顺序也应该是-lavutil -lavformat -lavcodec