在VS2017中编译FFmpeg,头文件是这样的:c++
#include "libavcodec/avcodec.h"
#include "libavutil/opt.h"
#include "libavutil/imgutils.h"
可是连接的时候却找不到函数。报错:bash
1>EncodeVideo.obj : error LNK2019: 没法解析的外部符号 "int __cdecl av_strerror(int,char *,unsigned __int64)" (?av_strerror@@YAHHPEAD_K@Z),该符号在函数 "char * __cdecl av_make_error_string(char *,unsigned __int64,int)" (?av_make_error_string@@YAPEADPEAD_KH@Z) 中被引用
1>EncodeVideo.obj : error LNK2019: 没法解析的外部符号 "struct AVFrame * __cdecl av_frame_alloc(void)" (?av_frame_alloc@@YAPEAUAVFrame@@XZ),该符号在函数 main 中被引用
1>EncodeVideo.obj : error LNK2019: 没法解析的外部符号 "void __cdecl av_frame_free(struct AVFrame * *)" (?av_frame_free@@YAXPEAPEAUAVFrame@@@Z),该符号在函数 main 中被引用
1>EncodeVideo.obj : error LNK2019: 没法解析的外部符号 "int __cdecl av_frame_get_buffer(struct AVFrame *,int)" (?av_frame_get_buffer@@YAHPEAUAVFrame@@H@Z),该符号在函数 main 中被引用
1>EncodeVideo.obj : error LNK2019: 没法解析的外部符号 "int __cdecl av_frame_make_writable(struct AVFrame *)" (?av_frame_make_writable@@YAHPEAUAVFrame@@@Z),该符号在函数 main 中被引用
1>EncodeVideo.obj : error LNK2019: 没法解析的外部符号 "struct AVCodecContext * __cdecl avcodec_alloc_context3(struct AVCodec const *)" (?avcodec_alloc_context3@@YAPEAUAVCodecContext@@PEBUAVCodec@@@Z),该符号在函数 main 中被引用
1>EncodeVideo.obj : error LNK2019: 没法解析的外部符号 "void __cdecl avcodec_free_context(struct AVCodecContext * *)" (?avcodec_free_context@@YAXPEAPEAUAVCodecContext@@@Z),该符号在函数 main 中被引用
1>EncodeVideo.obj : error LNK2019: 没法解析的外部符号 "int __cdecl avcodec_open2(struct AVCodecContext *,struct AVCodec const *,struct AVDictionary * *)" (?avcodec_open2@@YAHPEAUAVCodecContext@@PEBUAVCodec@@PEAPEAUAVDictionary@@@Z),该符号在函数 main 中被引用
1>EncodeVideo.obj : error LNK2019: 没法解析的外部符号 "struct AVPacket * __cdecl av_packet_alloc(void)" (?av_packet_alloc@@YAPEAUAVPacket@@XZ),该符号在函数 main 中被引用
1>EncodeVideo.obj : error LNK2019: 没法解析的外部符号 "void __cdecl av_packet_free(struct AVPacket * *)" (?av_packet_free@@YAXPEAPEAUAVPacket@@@Z),该符号在函数 main 中被引用
1>EncodeVideo.obj : error LNK2019: 没法解析的外部符号 "void __cdecl av_packet_unref(struct AVPacket *)" (?av_packet_unref@@YAXPEAUAVPacket@@@Z),该符号在函数 "void __cdecl encode(struct AVCodecContext *,struct AVFrame *,struct AVPacket *,struct _iobuf *)" (?encode@@YAXPEAUAVCodecContext@@PEAUAVFrame@@PEAUAVPacket@@PEAU_iobuf@@@Z) 中被引用
1>EncodeVideo.obj : error LNK2019: 没法解析的外部符号 "int __cdecl avcodec_send_frame(struct AVCodecContext *,struct AVFrame const *)" (?avcodec_send_frame@@YAHPEAUAVCodecContext@@PEBUAVFrame@@@Z),该符号在函数 "void __cdecl encode(struct AVCodecContext *,struct AVFrame *,struct AVPacket *,struct _iobuf *)" (?encode@@YAXPEAUAVCodecContext@@PEAUAVFrame@@PEAUAVPacket@@PEAU_iobuf@@@Z) 中被引用
1>EncodeVideo.obj : error LNK2019: 没法解析的外部符号 "int __cdecl avcodec_receive_packet(struct AVCodecContext *,struct AVPacket *)" (?avcodec_receive_packet@@YAHPEAUAVCodecContext@@PEAUAVPacket@@@Z),该符号在函数 "void __cdecl encode(struct AVCodecContext *,struct AVFrame *,struct AVPacket *,struct _iobuf *)" (?encode@@YAXPEAUAVCodecContext@@PEAUAVFrame@@PEAUAVPacket@@PEAU_iobuf@@@Z) 中被引用
1>EncodeVideo.obj : error LNK2019: 没法解析的外部符号 "struct AVCodec * __cdecl avcodec_find_encoder_by_name(char const *)" (?avcodec_find_encoder_by_name@@YAPEAUAVCodec@@PEBD@Z),该符号在函数 main 中被引用
1>EncodeVideo.obj : error LNK2019: 没法解析的外部符号 "int __cdecl av_opt_set(void *,char const *,char const *,int)" (?av_opt_set@@YAHPEAXPEBD1H@Z),该符号在函数 main 中被引用
检查后发现,在c++中调用c库,须要加:ide
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavutil/opt.h"
#include "libavutil/imgutils.h"
}
OK编译成功!函数
在使用VS2017编译FFmpeg时,遇到LNK2019错误,提示无法解析的外部符号。错误涉及到av_strerror、av_frame_alloc等多个函数。解决办法是在C++代码中添加`extern "C"`来包含FFmpeg的头文件,确保链接正确。完成此修改后,编译成功。
1911

被折叠的 条评论
为什么被折叠?



