error LNK2019: 无法解析的外部符号 "XXXXX"XXXX,该符号在函数XXX中被引用

如:在调用ffmpeg接口时,出现如下错误:

1>decede.obj : error LNK2019: 无法解析的外部符号 "struct AVFrame * __cdecl av_frame_alloc(void)" (?av_frame_alloc@@YAPAUAVFrame@@XZ),该符号在函数 _main 中被引用
1>decede.obj : error LNK2019: 无法解析的外部符号 "void __cdecl av_frame_free(struct AVFrame * *)" (?av_frame_free@@YAXPAPAUAVFrame@@@Z),该符号在函数 _main 中被引用
1>decede.obj : error LNK2019: 无法解析的外部符号 "struct AVCodecContext * __cdecl avcodec_alloc_context3(struct AVCodec const *)" (?avcodec_alloc_context3@@YAPAUAVCodecContext@@PBUAVCodec@@@Z),该符号在函数 _main 中被引用
1>decede.obj : error LNK2019: 无法解析的外部符号 "void __cdecl avcodec_free_context(struct AVCodecContext * *)" (?avcodec_free_context@@YAXPAPAUAVCodecContext@@@Z),该符号在函数 _main 中被引用
1>decede.obj : error LNK2019: 无法解析的外部符号 "int __cdecl avcodec_open2(struct AVCodecContext *,struct AVCodec const *,struct AVDictionary * *)" (?avcodec_open2@@YAHPAUAVCodecContext@@PBUAVCodec@@PAPAUAVDictionary@@@Z),该符号在函数 _main 中被引用
1>decede.obj : error LNK2019: 无法解析的外部符号 "struct AVPacket * __cdecl av_packet_alloc(void)" (?av_packet_alloc@@YAPAUAVPacket@@XZ),该符号在函数 _main 中被引用
1>decede.obj : error LNK2019: 无法解析的外部符号 "void __cdecl av_packet_free(struct AVPacket * *)" (?av_packet_free@@YAXPAPAUAVPacket@@@Z),该符号在函数 _main 中被引用
1>decede.obj : error LNK2019: 无法解析的外部符号 "struct AVCodec * __cdecl avcodec_find_decoder(enum AVCodecID)" (?avcodec_find_decoder@@YAPAUAVCodec@@W4AVCodecID@@@Z),该符号在函数 _main 中被引用
1>decede.obj : error LNK2019: 无法解析的外部符号 "int __cdecl avcodec_send_packet(struct AVCodecContext *,struct AVPacket const *)" (?avcodec_send_packet@@YAHPAUAVCodecContext@@PBUAVPacket@@@Z),该符号在函数 "void __cdecl decode(struct AVCodecContext *,struct AVFrame *,struct AVPacket *,char const *)" (?decode@@YAXPAUAVCodecContext@@PAUAVFrame@@PAUAVPacket@@PBD@Z) 中被引用
1>decede.obj : error LNK2019: 无法解析的外部符号 "int __cdecl avcodec_receive_frame(struct AVCodecContext *,struct AVFrame *)" (?avcodec_receive_frame@@YAHPAUAVCodecContext@@PAUAVFrame@@@Z),该符号在函数 "void __cdecl decode(struct AVCodecContext *,struct AVFrame *,struct AVPacket *,char const *)" (?decode@@YAXPAUAVCodecContext@@PAUAVFrame@@PAUAVPacket@@PBD@Z) 中被引用
1>decede.obj : error LNK2019: 无法解析的外部符号 "struct AVCodecParserContext * __cdecl av_parser_init(int)" (?av_parser_init@@YAPAUAVCodecParserContext@@H@Z),该符号在函数 _main 中被引用
1>decede.obj : error LNK2019: 无法解析的外部符号 "int __cdecl av_parser_parse2(struct AVCodecParserContext *,struct AVCodecContext *,unsigned char * *,int *,unsigned char const *,int,__int64,__int64,__int64)" (?av_parser_parse2@@YAHPAUAVCodecParserContext@@PAUAVCodecContext@@PAPAEPAHPBEH_J55@Z),该符号在函数 _main 中被引用
1>decede.obj : error LNK2019: 无法解析的外部符号 "void __cdecl av_parser_close(struct AVCodecParserContext *)" (?av_parser_close@@YAXPAUAVCodecParserContext@@@Z),该符号在函数 _main 中被引用
1>D:\TestPro\decede\Debug\decede.exe : fatal error LNK1120: 13 个无法解析的外部命令

可以保证的是,配置中,在检查包含目录、库目录、链接器输入和系统环境变量均设置无误的情况下,包含的文件要写成以下形式:

extern "C"
{
#include <libavcodec\avcodec.h>
#include <libavformat\avformat.h>
#include <libswscale\swscale.h>
#include <libavutil\pixfmt.h>
#include <libavutil\imgutils.h>
};

这种情况是因为,头文件中的函数定义在编译为 C 程序的文件中,而头文件是在 C++ 文件中不带 extern “C” 修饰符声明的。在此情况下,需要添加extern "C"修饰符。

发布了135 篇原创文章 · 获赞 67 · 访问量 23万+

猜你喜欢

转载自blog.csdn.net/y601500359/article/details/98845171