Saturday 30 April 2016

visual studio - Unresolved external symbols in C++ project



This is my situation (I am very new to C++ MFC coding and I am trying to debug an existing application project)




I use this line in my code (in a visual studio 2012 MFC project)




CoCreateInstance(CLSID_PortableDeviceValues, NULL,
CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&x));




While I run the project, i get a linker error like this





error LNK2001: unresolved external symbol _CLSID_PortableDeviceValues




This happens for all the CLSID values that I am referring to in the code. Like this




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




I checked for the declaration of "CLSID_PortableDeviceValues" and it was found in "PortableDeviceTypes.h" and I have imported that library as well.



I do not get any compiler error, but run into the linker errors mentioned above..




Can someone please help me out here. I could not resolve this ..


Answer



You will need to add PortableDeviceGUIDs.lib to your project.
(Look up the section "Requirements" in the MSDN documentation for IPortableDeviceValues)



When the linker builds your project, it is looking for the implementation data that is behind the identifier CLSID_PortableDeviceValues. This data is in the library PortableDeviceGUIDs.lib, and the linker has to be told to use this library.



The header file you included in your source code only declares the symbol "CLSID_PortableDeviceValues", without importing its implementation.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...