博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【ffmpeg】编译时报错:error: undefined reference to `av...
阅读量:4263 次
发布时间:2019-05-26

本文共 1685 字,大约阅读时间需要 5 分钟。

1、问题描述

昨天使用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*)'
2、原因查找

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” 。

3、解决方法

在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/

你可能感兴趣的文章
TED演讲:Jeff Hawkins.大脑的工作原理是什么
查看>>
Windows命令行提示
查看>>
梳理《前目的地》
查看>>
ArrayList底层实现
查看>>
ACM寒假培训——各种排序
查看>>
CF417D——Cunning Gena(状态压缩DP)
查看>>
HDU1074——Doing Homework(状态压缩DP)
查看>>
POJ1113——Wall(凸包)
查看>>
HDU3847——Trash Removal(凸包,枚举)
查看>>
文档滚动对 scrollTop scrollLeft的兼容性封装
查看>>
Python笔记:lambda表达式
查看>>
Python笔记:对文件的读写操作
查看>>
Python笔记:详解使用Python列表创建ndarray
查看>>
Typescript 中的类的应用
查看>>
Python笔记:NumPy中的布尔型索引使用举例
查看>>
Python笔记:访问或修改 Pandas Series 中的元素以及相关运算
查看>>
Python笔记:Pandas DataFrames 的使用
查看>>
Python笔记:在Pandas中处理NaN值
查看>>
Typescript 中的接口的实现
查看>>
Typescript中的泛型的使用
查看>>