出错状况:
使用SVN 获取ffmpeg
svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
安装成功。
编译简单例程:
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <stdio.h>
int main(int argc,char*argv[])
{
av_register_all();
return 0;
}
使用:gcc examp.c -lavcodec -lavformat -lavdevice -lavutil 编译。
报N错。
/home/lnstree/ffmpegSrc/ffmpeg/libavcodec/pthread_frame.c:770: undefined reference to `av_buffer_alloc'
/usr/local/lib/libavcodec.a(pthread_frame.o): In function `ff_thread_get_format':
/home/lnstree/ffmpegSrc/ffmpeg/libavcodec/pthread_frame.c:822: undefined reference to `av_log'
/usr/local/lib/libavcodec.a(pthread_frame.o): In function `ff_thread_await_progress':
/home/lnstree/ffmpegSrc/ffmpeg/libavcodec/pthread_frame.c:502: undefined reference to `av_log'
/usr/local/lib/libavcodec.a(pthread_frame.o): In function `release_delayed_buffers':
/home/lnstree/ffmpegSrc/ffmpeg/libavcodec/pthread_frame.c:302: undefined reference to `av_frame_unref'
/usr/local/lib/libavcodec.a(pthread_frame.o): In function `submit_packet':
/home/lnstree/ffmpegSrc/ffmpeg/libavcodec/pthread_frame.c:336: undefined reference to `av_buffer_unref'
/home/lnstree/ffmpegSrc/ffmpeg/libavcodec/pthread_frame.c:339: undefined reference to `av_buffer_ref'
/usr/local/lib/libavcodec.a(pthread_frame.o): In function `ff_thread_decode_frame':
/home/lnstree/ffmpegSrc/ffmpeg/libavcodec/pthread_frame.c:449: undefined reference to `av_frame_move_ref'
/usr/local/lib/libavcodec.a(pthread_frame.o): In function `update_context_from_user':
/home/lnstree/ffmpegSrc/ffmpeg/libavcodec/pthread_frame.c:271: undefined reference to `av_realloc'
/usr/local/lib/libavcodec.a(pthread_frame.o): In function `submit_packet':
/home/lnstree/ffmpegSrc/ffmpeg/libavcodec/pthread_frame.c:341: undefined reference to `av_fast_malloc'
/usr/local/lib/libavcodec.a(pthread_frame.o): In function `update_context_from_user':
/home/lnstree/ffmpegSrc/ffmpeg/libavcodec/pthread_frame.c:274: undefined reference to `av_free'
/usr/local/lib/libavcodec.a(pthread_frame.o): In function `submit_packet':
/home/lnstree/ffmpegSrc/ffmpeg/libavcodec/pthread_frame.c:298: undefined reference to `av_log'
/usr/local/lib/libavcodec.a(pthread_frame.o): In function `release_delayed_buffers':
/home/lnstree/ffmpegSrc/ffmpeg/libavcodec/pthread_frame.c:302: undefined reference to `av_frame_unref'
。。。。。
解决方法:
将make install 安装的 libavxxx.pc 文件移到默认pkg-config 目录中。
本机make install libavxxxx.pc 文件 在/usr/local/lib/pkgconfig
使用命令 cp /usr/local/lib/pkgconfig/* /usr/share/pkgconfig/ 拷贝。
注:ffmpeg 源码 附带 例程。 make install 后 例程 在/usr/local/share/ffmpeg/examples 下。 里面有Makefile 文件。
在该目录下 make。(前提 所有 libavxxx.pc 已经移入默认目录/usr/share/pkconfig/)
make :
cc decoding_encoding.o -pthread -L/usr/local/lib -lavdevice -lavfilter -lavformat -lavcodec -ldl -lX11 -lasound -lSDL -lpthread -lopencore-amrwb -lopencore-amrnb -lmp3lame -lgsm -lfaac -lz -lrt -lswresample -lswscale -lavutil -lm -lm -o decoding_encoding
cc demuxing_decoding.o -pthread -L/usr/local/lib -lavdevice -lavfilter -lavformat -lavcodec -ldl -lX11 -lasound -lSDL -lpthread -lopencore-amrwb -lopencore-amrnb -lmp3lame -lgsm -lfaac -lz -lrt -lswresample -lswscale -lavutil -lm -o demuxing_decoding
cc filtering_video.o -pthread -L/usr/local/lib -lavdevice -lavfilter -lavformat -lavcodec -ldl -lX11 -lasound -lSDL -lpthread -lopencore-amrwb -lopencore-amrnb -lmp3lame -lgsm -lfaac -lz -lrt -lswresample -lswscale -lavutil -lm -o filtering_video
cc filtering_audio.o -pthread -L/usr/local/lib -lavdevice -lavfilter -lavformat -lavcodec -ldl -lX11 -lasound -lSDL -lpthread -lopencore-amrwb -lopencore-amrnb -lmp3lame -lgsm -lfaac -lz -lrt -lswresample -lswscale -lavutil -lm -o filtering_audio
cc metadata.o -pthread -L/usr/local/lib -lavdevice -lavfilter -lavformat -lavcodec -ldl -lX11 -lasound -lSDL -lpthread -lopencore-amrwb -lopencore-amrnb -lmp3lame -lgsm -lfaac -lz -lrt -lswresample -lswscale -lavutil -lm -o metadata
cc muxing.o -pthread -L/usr/local/lib -lavdevice -lavfilter -lavformat -lavcodec -ldl -lX11 -lasound -lSDL -lpthread -lopencore-amrwb -lopencore-amrnb -lmp3lame -lgsm -lfaac -lz -lrt -lswresample -lswscale -lavutil -lm -lm -o muxing
cc resampling_audio.o -pthread -L/usr/local/lib -lavdevice -lavfilter -lavformat -lavcodec -ldl -lX11 -lasound -lSDL -lpthread -lopencore-amrwb -lopencore-amrnb -lmp3lame -lgsm -lfaac -lz -lrt -lswresample -lswscale -lavutil -lm -lm -o resampling_audio
cc scaling_video.o -pthread -L/usr/local/lib -lavdevice -lavfilter -lavformat -lavcodec -ldl -lX11 -lasound -lSDL -lpthread -lopencore-amrwb -lopencore-amrnb -lmp3lame -lgsm -lfaac -lz -lrt -lswresample -lswscale -lavutil -lm -o scaling_video
cc transcode_aac.o -pthread -L/usr/local/lib -lavdevice -lavfilter -lavformat -lavcodec -ldl -lX11 -lasound -lSDL -lpthread -lopencore-amrwb -lopencore-amrnb -lmp3lame -lgsm -lfaac -lz -lrt -lswresample -lswscale -lavutil -lm -o transcode_aac
然后 使用 该make 显示的编译参数
gcc example.c -lavdevice -lavfilter -lavformat -lavcodec -ldl -lX11 -lasound -lSDL -lpthread -lopencore-amrwb -lopencore-amrnb -lmp3lame -lgsm -lfaac -lz -lrt -lswresample -lswscale -lavutil -lm
; D 偷懒,一大堆依赖看不懂,能用就行。
成功!!
参考网址:
http://blog.csdn.net/ajaxhe/article/details/9499815 有关pkg-config