经典错误::error LNK2019:无法解析的外部符号 ,该符号在函数**中被引用

摘要:
pCodec){//信息格式;//返回FALSE;}avcodec_open2;//打开解码器intframeFinished=0;AVFrame*pFrame;pFrame=avcodec_alloc_frame();AVPacketavPacket;av_ init_包;AVPicturepRGB帧;avpicture_分配;SwsContext*pSwsContext;pSwsContext=sws_ getContext;而{if{avcodec_decode_video2;//解码if{sws_scale;}保存框架;//保存数据av_ free_数据包;//Release}}错误1:运行后出现错误提示:1˃111。obj:errorLNK2019:未解析的外部符号“void _ cdeclav_free_packet”(?avcodec_decode_video2@@YAHPAUAVCodecContext@@PAUAVFrame@@PAHPUAVPacket@@@Z),位于函数_1˃111中?

将视频逐帧提取,转换为图片保存下来:

源代码:

#include <cv.h>
#include <highgui.h>

#if 1 //错误一//错误一//错误一//错误一//错误一//错误一//错误一//错误一//错误一//错误一//错误一//错误一
#include <libavcodec/avcodec.h>
#include <libavdevice/avdevice.h>
#include <libavformat/avformat.h>
#endif

#include "libRtsp2RGB24Sdk.h"
#include "libRtsp2RGB24Header.h"

int nFrameWidth=1920, nFrameHeight=1080;
void SaveFrame(AVPicture pFrameRGB, int width, int height)
{
IplImage * dst = cvCreateImage(cvSize(nFrameWidth,nFrameHeight),8,3);;
LPVOID pMem = (LPVOID)pFrameRGB.data[0];

memcpy(dst->imageData,pMem,nFrameWidth*nFrameHeight*3);

cvSaveImage("D:\pic.jpg",dst);
}

void main()
{
avcodec_register_all();
av_register_all();
avformat_network_init();

AVFormatContext *pFormatCtx;

#if 1 //错误二//错误二//错误二//错误二//错误二//错误二//错误二//错误二//错误二//错误二//错误二//错误二
pFormatCtx = avformat_alloc_context(); //必不可少!
#endif

char *filename = "222.mpg"; // "C:\Users\HYZ\Desktop\2.avi";

avformat_open_input(&pFormatCtx, filename, NULL, 0);

av_find_stream_info(pFormatCtx);

int videoStream=-1;
for(int i=0; i<pFormatCtx->nb_streams; i++)
if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
{
videoStream=i;
break;
}
if(videoStream == -1)
{
//sInfo.Format("视频中无视频解码器信息");
//return FALSE;
}

AVCodec * pCodec;
AVCodecContext * pCodecCtx;
pCodecCtx = pFormatCtx->streams[videoStream]->codec;
pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
if (!pCodec)
{
//sInfo.Format("无法找到视频解码器");
//return FALSE;
}
avcodec_open2(pCodecCtx, pCodec, NULL); // 打开解码器

int frameFinished = 0;

AVFrame *pFrame;
pFrame=avcodec_alloc_frame();

AVPacket avPacket;
av_init_packet(&avPacket);

AVPicture pRGBFrame;
avpicture_alloc(&pRGBFrame,PIX_FMT_RGB24,nFrameWidth,nFrameHeight);

SwsContext * pSwsContext;
pSwsContext = sws_getContext(nFrameWidth, nFrameHeight, pCodecCtx->pix_fmt, nFrameWidth, nFrameHeight,
PIX_FMT_BGR24,SWS_FAST_BILINEAR,NULL,NULL,NULL);

while(av_read_frame(pFormatCtx, &avPacket)>=0)
{
if(avPacket.stream_index==videoStream)
{
avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &avPacket);//解码

if(frameFinished>0)
{
sws_scale(pSwsContext, pFrame->data, pFrame->linesize, 0, nFrameHeight, pRGBFrame.data, pRGBFrame.linesize);
}

SaveFrame(pRGBFrame, pCodecCtx->width, pCodecCtx->height); //保存数据

av_free_packet(&avPacket); //释放
}
}
}

错误一:

运行后错误提示:

1>111.obj : error LNK2019: 无法解析的外部符号 "void __cdecl av_free_packet(struct AVPacket *)" (?av_free_packet@@YAXPAUAVPacket@@@Z),该符号在函数 _main 中被引用
1>111.obj : error LNK2019: 无法解析的外部符号 "int __cdecl avcodec_decode_video2(struct AVCodecContext *,struct AVFrame *,int *,struct AVPacket const *)" (?avcodec_decode_video2@@YAHPAUAVCodecContext@@PAUAVFrame@@PAHPBUAVPacket@@@Z),该符号在函数 _main 中被引用
1>111.obj : error LNK2019: 无法解析的外部符号 "int __cdecl av_read_frame(struct AVFormatContext *,struct AVPacket *)" (?av_read_frame@@YAHPAUAVFormatContext@@PAUAVPacket@@@Z),该符号在函数 _main 中被引用
1>111.obj : error LNK2019: 无法解析的外部符号 "int __cdecl avpicture_alloc(struct AVPicture *,enum AVPixelFormat,int,int)" (?avpicture_alloc@@YAHPAUAVPicture@@W4AVPixelFormat@@HH@Z),该符号在函数 _main 中被引用
1>111.obj : error LNK2019: 无法解析的外部符号 "void __cdecl av_init_packet(struct AVPacket *)" (?av_init_packet@@YAXPAUAVPacket@@@Z),该符号在函数 _main 中被引用
1>111.obj : error LNK2019: 无法解析的外部符号 "struct AVFrame * __cdecl avcodec_alloc_frame(void)" (?avcodec_alloc_frame@@YAPAUAVFrame@@XZ),该符号在函数 _main 中被引用
1>111.obj : error LNK2019: 无法解析的外部符号 "int __cdecl avcodec_open2(struct AVCodecContext *,struct AVCodec const *,struct AVDictionary * *)" (?avcodec_open2@@YAHPAUAVCodecContext@@PBUAVCodec@@PAPAUAVDictionary@@@Z),该符号在函数 _main 中被引用
1>111.obj : error LNK2019: 无法解析的外部符号 "struct AVCodec * __cdecl avcodec_find_decoder(enum AVCodecID)" (?avcodec_find_decoder@@YAPAUAVCodec@@W4AVCodecID@@@Z),该符号在函数 _main 中被引用
1>111.obj : error LNK2019: 无法解析的外部符号 "int __cdecl av_find_stream_info(struct AVFormatContext *)" (?av_find_stream_info@@YAHPAUAVFormatContext@@@Z),该符号在函数 _main 中被引用
1>111.obj : error LNK2019: 无法解析的外部符号 "int __cdecl avformat_open_input(struct AVFormatContext * *,char const *,struct AVInputFormat *,struct AVDictionary * *)" (?avformat_open_input@@YAHPAPAUAVFormatContext@@PBDPAUAVInputFormat@@PAPAUAVDictionary@@@Z),该符号在函数 _main 中被引用
1>111.obj : error LNK2019: 无法解析的外部符号 "struct AVFormatContext * __cdecl avformat_alloc_context(void)" (?avformat_alloc_context@@YAPAUAVFormatContext@@XZ),该符号在函数 _main 中被引用
1>111.obj : error LNK2019: 无法解析的外部符号 "int __cdecl avformat_network_init(void)" (?avformat_network_init@@YAHXZ),该符号在函数 _main 中被引用
1>111.obj : error LNK2019: 无法解析的外部符号 "void __cdecl av_register_all(void)" (?av_register_all@@YAXXZ),该符号在函数 _main 中被引用
1>111.obj : error LNK2019: 无法解析的外部符号 "void __cdecl avcodec_register_all(void)" (?avcodec_register_all@@YAXXZ),该符号在函数 _main 中被引用
1>C:UsersHYZDesktop测试环境集stream22.exe : fatal error LNK1120: 14 个无法解析的外部命令

解决方法:注释掉错误一,不包含那些头文件即可。包含太多的文件也会发生无法解析的错误,搞不懂。

错误二:

运行到avformat_open_input()函数处停止,而且F11也进不去。

弹出错误提示框:stream22.exe中的*****处有未经处理的异常:0xc0000005:读取位置0xccccccccccc时发生访问冲突

解决方法:分配内存空间即可:这类错误一般是内存错误导致,重点排查内存分配。

免责声明:文章转载自《经典错误::error LNK2019:无法解析的外部符号 ,该符号在函数**中被引用》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇资深技术专家崮德在阿里管理研发团队的实践和思考gin连接mysql数据库下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

virsh 连接虚拟机 (vnc 或 控制台)

第一种方法:1.如果虚拟机登录方法是VNC,请在ubuntu机器上安装vncviewer。在虚拟机的配置xml中,安装vncviewer$apt-geinstallvncviewer以查看虚拟机的端口地址$virshvncdisplaycontroller通过端口地址显示:0...

IDEA 运行键是灰色

版权声明:本文为博主原创文章,遵循CC4.0BY-SA版权协议。转载请附上原始来源链接和本声明。本文链接:https://blog.csdn.net/Butterfly_resting/article/details/89388149原因是我们的新项目没有选择源目录,如图所示:解决方案:IDEA提供了选择源目录的快速设置。右键单击src并选择MarkDire...

20、EVE-NG华丽登场Openstack镜像,体验私有云!

EVE-NG华丽登场Openstack镜像,体验私有云!为了推动Cloud技术在国内更快速的发展,本人决定为EVE-NG定制一个Openstack私有云系统的镜像,来提升工程师个人的技术实力,横向拓宽技术知识面,以应对IT技术高速迭代,快速发展的现状。当然,您可以将Openstack设备连接到其他拓补中,但设备所在的网络必须是10.0.0.0/24,并且网关...

如何给LINUX红帽子版本配置IP(转)

如果需要绑定另一个IP地址,只需在文件名中添加一个,并在文件中的DEVICE中添加eth0:x。LINUX可以支持多达255个IP别名,多个网卡绑定到一个IP地址,并且可以使用多个网卡创建具有相同IP地址的虚拟网卡。事实上,这种技术已经存在于Sun和Cisco中,它们分别被称为中继和以太网信道技术。在Linux中,这种技术被称为绑定。...

sqlmap 安装使用

Id=1“”8)从配置文件加载攻击目标,并使用参数“-c”指定配置文件。Sqlmap将解析配置文件并根据配置文件的配置执行操作。sqlmap conf文件的安装目录中有一个名为sqlmap的文件,它是配置文件的模板。Id=1“--当前用户#列出数据库sqlmap.py u的所有用户”http://192.168.12.157:30336/#/login?...

Swift开发中 JSON对象/JSON字符串/Data的互转

本文将介绍常见的转换#pragmark JSON(object)------˃JSON string 1,原生方法//JSON------˃data------˃JSON string letdata=try?JSON序列化。data#pragmark数据------˃JSON(对象)1.本机方法guardletarray=try?[[String:AnyO...