c++mfcincludemsxmllnk2005

C++ MSXML, LINK error "already defined in obj"


I don't understand what I did wrong

Common.h

#pragma once
#include "Flisr.h"
#import <msxml3.dll> named_guids
MSXML2::IXMLDOMDocumentPtr   m_plDomDocument;
MSXML2::IXMLDOMElementPtr    m_pDocRoot;

Common.cpp

#include "Common.h"

//some functions

Flisr.cpp

#include "Flisr.h"
#include "Common.h"

//some functions from Common

Errors are:

error LNK2005: "class _com_ptr_t<class _com_IIID<struct MSXML2::IXMLDOMDocument,&struct __s_GUID const _GUID_2933bf81_7b36_11d2_b20e_00c04f983e60> > m_plDomDocument" (?m_plDomDocument@@3V?$_com_ptr_t@V?$_com_IIID@UIXMLDOMDocument@MSXML2@@$1?_GUID_2933bf81_7b36_11d2_b20e_00c04f983e60@@3U__s_GUID@@B@@@@A) already defined in Common.obj

error LNK2005: "class _com_ptr_t<class _com_IIID<struct MSXML2::IXMLDOMElement,&struct __s_GUID const _GUID_2933bf86_7b36_11d2_b20e_00c04f983e60> > m_pDocRoot" (?m_pDocRoot@@3V?$_com_ptr_t@V?$_com_IIID@UIXMLDOMElement@MSXML2@@$1?_GUID_2933bf86_7b36_11d2_b20e_00c04f983e60@@3U__s_GUID@@B@@@@A) already defined in Common.obj

Solution

  • Each time you "#include "Common.h", you are defining a new set of objects (global variables) called m_plDomDocument and m_pDocRoot. Only one of each is permitted for the scope of the program, hence the error that they are already defined.