VS編譯FFmpeg時,報錯“error LNK2019: 無法解析的外部符號”

在VS2017中編譯FFmpeg,頭文件是這樣的:

#include "libavcodec/avcodec.h"
#include "libavutil/opt.h"
#include "libavutil/imgutils.h"

但是鏈接的時候卻找不到函數。報錯:

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庫,需要加:


extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavutil/opt.h"
#include "libavutil/imgutils.h"
}

OK編譯成功!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章