本文共 1685 字,大约阅读时间需要 5 分钟。
昨天使用ffmpeg库编译demo一切正常,今天再次链接ffmpeg库时报了一堆错误:
error: undefined reference to `av_frame_alloc()'error: undefined reference to `avio_close(AVIOContext*)'error: undefined reference to `avcodec_find_encoder(AVCodecID)'error: undefined reference to `avcodec_alloc_context3(AVCodec const*)'error: undefined reference to `av_opt_set(void*, char const*, char const*, int)'error: undefined reference to `avcodec_open2(AVCodecContext*, AVCodec const*, AVDictionary**)'error: undefined reference to `av_frame_alloc()'error: undefined reference to `av_image_alloc(unsigned char**, int*, int, int, AVPixelFormat, int)'error: undefined reference to `avformat_alloc_context()'error: undefined reference to `av_malloc(unsigned long)'error: undefined reference to `avio_alloc_context(unsigned char*, int, int, void*, int (*)(void*, unsigned char*, int), int (*)(void*, unsigned char*, int), long (*)(void*, long, int))'error: undefined reference to `avformat_alloc_output_context2(AVFormatContext**, AVOutputFormat*, char const*, char const*)'error: undefined reference to `avformat_free_context(AVFormatContext*)'
1> 确认过ffmpeg库链接路径、库名字都对
-L[安装ffmpeg路径]/lib -lavcodec -lavformat -lavutil -lswscale -lpthread -lm -lswresample -lx264
2> 以为是系统以前安装的旧版本ffmpeg库造成干扰,将/usb/lib/x86_64-linux-gnu/下的ffmpeg库删除,还是不行。
3> 认真比对昨天的demo,发现,昨天是用gcc编译、今天是用g++编译。百度后才发现 ffmpeg库的接口都是c函数,其头文件也没有extern "C"的声明,所以在cpp文件里调用ffmpeg函数要加extern “C” 。在c++中使用ffmpeg时,需要用extern “C” 声明ffmpeg的头文件。
#ifdef __cplusplusextern "C" { #endif#include#include #include #include #include #include #include #include #ifdef __cplusplus} // endof extern "C"#endif
转载地址:http://gdmei.baihongyu.com/