2019编译ffepeg vs_VS编译FFmpeg时,报错“error LNK2019: 没法解析的外部符号”

在使用VS2017编译FFmpeg时,遇到LNK2019错误,提示无法解析的外部符号。错误涉及到av_strerror、av_frame_alloc等多个函数。解决办法是在C++代码中添加`extern "C"`来包含FFmpeg的头文件,确保链接正确。完成此修改后,编译成功。

在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编译成功!函数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值