MediaFoundation中使用DXVA2编译遇LNK2001错误的解决咨询
问题描述
我正在使用MediaFoundation实现摄像头采集功能,由于我的摄像头支持H264预览,因此按照微软官方文档指导在MediaFoundation中使用DXVA2.0。以下是我的部分代码:
#include <evr.h> #include <mfapi.h> #include <mfidl.h> #include <mfreadwrite.h> #include <mferror.h> #include <strsafe.h> #include <ks.h> #include <ksproxy.h> #include <Vidcap.h> #include <Ksmedia.h> #include <d3d9.h> #include <dxva2api.h> #pragma comment(lib, "mf.lib") #pragma comment(lib, "mfplat.lib") #pragma comment(lib, "mfplay.lib") #pragma comment(lib, "mfreadwrite.lib") #pragma comment(lib, "mfuuid.lib") #pragma comment(lib, "evr.lib") #pragma comment(lib, "strmiids.lib") #pragma comment(lib, "d3d9.lib") #pragma comment(lib, "dxva2.lib") .... HANDLE pDeviceHandle = nullptr; hr = pD3DManager->OpenDeviceHandle(&pDeviceHandle); if (hr != S_OK) return -1; IDirectXVideoDecoderService *pDirectXVideoDecoderService = nullptr; hr = pD3DManager->GetVideoService(pDeviceHandle, IID_PPV_ARGS(&pDirectXVideoDecoderService)); if (hr != S_OK) return -1; UINT guidCount = 0; GUID *pGUIDs = nullptr; hr = pDirectXVideoDecoderService->GetDecoderDeviceGuids(&guidCount, &pGUIDs); if (hr != S_OK) return -1; GUID guid; for (UINT i = 0; i < guidCount; ++i) { if (pGUIDs != nullptr) { guid = pGUIDs[i]; // DXVA2_ModeH264_VLD_Stereo_Progressive_NoFGT // DXVA2_ModeH264_VLD_Stereo_NoFGT // DXVA2_ModeH264_VLD_NoFGT if (IsEqualGUID(guid, DXVA2_ModeH264_VLD_NoFGT)) break; } }
编译链接时出现如下错误:
Severity Code Description Project File Line Suppression State Details Error LNK2001 unresolved external symbol DXVA2_ModeH264_E DDemo D:\RHCTProject\VisualStudioPro\DDemo\mediacapture.obj 1 Severity Code Description Project File Line Suppression State Details Error LNK1120 1 unresolved externals DDemo D:\RHCTProject\VisualStudioPro\DDemo\x64\Debug\DDemo.exe 1
解决方法
- 排查代码拼写:错误提示的
DXVA2_ModeH264_E并非你代码中显式使用的GUID,检查整个代码文件是否存在拼写错误,不小心引用了这个未定义的标识符,发现后修正为正确的GUID名称。 - 导出DXVA2 GUID定义:在包含
dxva2api.h头文件之前,添加#define DXVA2API_IMPLEMENTATION宏,该宏会触发头文件中GUID的导出定义,修改后的头文件包含片段如下:#define DXVA2API_IMPLEMENTATION #include <dxva2api.h> - 确认库链接有效性:虽然代码中已经通过
#pragma comment(lib, "dxva2.lib")指定链接库,仍可手动在项目属性的「链接器 -> 输入 -> 附加依赖项」中添加dxva2.lib,避免编译指令失效的情况。 - 检查Windows SDK版本:确保使用的Windows SDK版本包含完整的DXVA2相关定义,建议使用Windows 10或更高版本的SDK。
内容的提问来源于stack exchange,提问作者World
相关产品推荐
相关产品推荐

