问题的现象:
1>H264Decode.obj : error LNK2019: 无法解析的外部符号 "struct AVFrame * __cdecl avcodec_alloc_frame(void)" (?avcodec_alloc_frame@@YAPAUAVFrame@@XZ),该符号在函数 "public: int __thiscall CH264Decode::avc_decode_init(int,int)" (?avc_decode_init@CH264Decode@@QAEHHH@Z) 中被引用
1>H264Decode.obj : error LNK2019: 无法解析的外部符号 "int __cdecl avcodec_open(struct AVCodecContext *,struct AVCodec *)" (?avcodec_open@@YAHPAUAVCodecContext@@PAUAVCodec@@@Z),该符号在函数 "public: int __thiscall CH264Decode::avc_decode_init(int,int)" (?avc_decode_init@CH264Decode@@QAEHHH@Z) 中被引用
1>H264Decode.obj : error LNK2019: 无法解析的外部符号 "struct AVCodecContext * __cdecl avcodec_alloc_context(void)" (?avcodec_alloc_context@@YAPAUAVCodecContext@@XZ),该符号在函数 "public: int __thiscall CH264Decode::avc_decode_init(int,int)" (?avc_decode_init@CH264Decode@@QAEHHH@Z) 中被引用
1>H264Decode.obj : error LNK2019: 无法解析的外部符号 "struct AVCodec * __cdecl avcodec_find_decoder(enum CodecID)"
网上的解决方法的总结:
1.添加:
#ifdef __cplusplus
extern "C"
{
#pragma comment (lib, "Ws2_32.lib")
#pragma comment (lib, "avcodec.lib")
#pragma comment (lib, "avdevice.lib")
#pragma comment (lib, "avfilter.lib")
#pragma comment (lib, "avformat.lib")
#pragma comment (lib, "avutil.lib")
#pragma comment (lib, "swresample.lib")
#pragma comment (lib, "swscale.lib")
};
#endif2.仅添加:
extern “c”
3.我试了上面两种方法,但是都不行。于是我参考我手头上已有的一个项目:avplayer.。参考他的cpp文件时如何处理这个无法链接的问题的。
它的解决方法与上面类似,但是在写法上有所不同
他的做法是:
#ifdef __cplusplus
extern "C" {
#endif
#include<.....>
void main()
{
//////
/////
}
#ifdef __cplusplus
}
#endif
把main函数包在宏里面。顺利的解决了问题。
参考网址:
http://www.360doc.com/content/13/0502/17/9192936_282472350.shtml
http://blog.sina.com.cn/s/blog_48dc8a0001017p0u.html

本文详细介绍了遇到H264视频解码时出现的链接错误问题,并提供了两种常见的解决方案:一是通过宏定义和外部库声明来链接所需的AV库;二是将main函数包裹在特定的宏定义内,从而成功解决链接问题。同时,通过参考一个现有项目(avplayer),展示了另一种处理此类问题的方法。
841

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



