FFmpeg error LNK2019:无法解析的外部符号avcodec_register_all(),该符号在函数中XXX被引用的解决方法

关于FFmpeg包错误 LNK2019问题解决方法

错误 LNK2019 无法解析的外部符号 “void __cdecl avcodec_register_all(void)” (?avcodec_register_all@@YAXXZ),该符号在函数 main 中被引用
错误 LNK2019 无法解析的外部符号 “int __cdecl avformat_network_init(void)” (?avformat_network_init@@YAHXZ),该符号在函数 main 中被引用
错误 LNK2019 无法解析的外部符号 “struct AVFormatContext * __cdecl avformat_alloc_context(void)” (?avformat_alloc_context@@YAPEAUAVFormatContext@@XZ),该符号在函数 main 中被引用
错误 LNK2019 无法解析的外部符号 “int __cdecl avformat_open_input(struct AVFormatContext * *,char const *,struct AVInputFormat *,struct AVDictionary * *)” (avformat_open_input@@YAHPEAPEAUAVFormatContext@@PEBDPEAUAVInputFormat@@PEAPEAUAVDictionary@@@Z),该符号在函数 main 中被引用

原因

网上看了很多文章。有说没有lib,dll没有的。还有让我直接注释掉的。我使用的是vs2019+ffmpeg的库。 avcodec_register_all()函数报错。原因是因为这个.h文件原来是用C写的。C++中要是用的话要用下面的方式才可以。

错误代码


#include "myProject.h"
#include <stdio.h> 
#include <Windows.h>
#include "libavformat/avformat.h"
int main()
{
	AVFormatContext* pFormatCtx;
	int             i, videoindex;
	AVCodecContext* pCodecCtx;
	AVCodec* pCodec;
	// Init
	avcodec_register_all(); //注册常用包
	avformat_network_init();//初始化网络
	pFormatCtx = avformat_alloc_context();    //分配内存
	if (avformat_open_input(&pFormatCtx, "rtmp://58.200.131.2:1935/livetv/gxtv", NULL, NULL) != 0) {   
		printf("Couldn't open input stream.\n");
		return -1;
	}
	return 0;
}

正确代码

#include "myProject.h"
#include <stdio.h> 
#include <Windows.h>
#define __STDC_CONSTANT_MACROS

#ifdef _WIN32
//Windows
extern "C"
{
#include "libavformat/avformat.h"
};
#else
//Linux...
#ifdef __cplusplus
extern "C"
{
#endif
#include <libavformat/avformat.h>
#ifdef __cplusplus
};
#endif
#endif

int main()
{
	AVFormatContext* pFormatCtx;
	int             i, videoindex;
	AVCodecContext* pCodecCtx;
	AVCodec* pCodec;
	// Init
	avcodec_register_all(); //注册常用包
	avformat_network_init();//初始化网络
	pFormatCtx = avformat_alloc_context();    //分配内存
	if (avformat_open_input(&pFormatCtx, "rtmp://58.200.131.2:1935/livetv/gxtv", NULL, NULL) != 0) {   
		printf("Couldn't open input stream.\n");
		return -1;
	}
	return 0;
}
  • 6
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值