#include "libavformat/avformat.h"// 引用av_register_al()函数的.h
#pragma comment(lib,"avformat.lib")// 引用av_register_al()函数的.lib
工程里配置avformat.h包含的目录
工程里配置avformat.lib包含的目录
void CtestDlg::decode(void)
{av_register_all();// 初始化libavformat/libavcodec
...
}
出现链接错误:
错误原因:
av_register_all()函数是用C编写的,因此在包含#include时,要加在extern "C"{},这样VS在编译的时候在av_register_all()函数名前不会加上其他字符。这个错误导致的原因是:编译时,由于没有加extern "C",所以av_register_all()函数有可能被编码成了abc_av_register_all(),所以在链接avformat.lib时,avformat.lib里找不到abc_av_register_all()出错。
修改后的代码:
extern "C"
{
#include "libavformat/avformat.h"
}
#pragma comment(lib,"avformat.lib")
void CtestDlg::decode(void)
{av_register_all();// 初始化libavformat/libavcodec
...
}
编译链接成功。。。。