这是我的情况(我对 C++ MFC 编码很陌生,我正在尝试调试现有的应用程序项目)
我在我的代码中使用了这一行(在 visual studio 2012 MFC 项目中)
CoCreateInstance(CLSID_PortableDeviceValues, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&x));
当我运行这个项目时,我收到这样的链接器错误
error LNK2001: unresolved external symbol _CLSID_PortableDeviceValues
我在代码中引用的所有 CLSID 值都会发生这种情况。像这样
error LNK2001: unresolved external symbol _CLSID_PortableDeviceKeyCollection
error LNK2001: unresolved external symbol _IID_IPortableDeviceEventCallback
error LNK2001: unresolved external symbol _CLSID_PortableDeviceManager
error LNK2001: unresolved external symbol _CLSID_PortableDeviceServiceFTM
我检查了“CLSID_PortableDeviceValues”的声明,在“PortableDeviceTypes.h”中找到了它,我也导入了那个库。
我没有收到任何编译器错误,但遇到了上述链接器错误..
有人可以帮我解决这个问题吗?我无法解决这个问题..
最佳答案
您需要将 PortableDeviceGUIDs.lib 添加到您的项目中。
(查看 MSDN documentation for IPortableDeviceValues 中的“要求”部分)
当链接器构建您的项目时,它会查找标识符 CLSID_PortableDeviceValues
后面的实现数据。此数据位于库 PortableDeviceGUIDs.lib 中,必须告知链接器使用此库。
您在源代码中包含的头文件仅声明了符号“CLSID_PortableDeviceValues”,而没有导入其实现。
关于c++ - C++ 项目中未解析的外部符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19690487/