C ++ MSXML,LINK错误"已在obj"中定义

时间:2017-04-06 08:35:50

标签: c++ mfc include msxml lnk2005

我不明白我做错了什么

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

错误是:

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

1 个答案:

答案 0 :(得分:0)

每次"#include "Common.h",您都要定义一组名为m_plDomDocumentm_pDocRoot的新对象(全局变量)。每个程序的范围只允许其中一个,因此它们已经定义了错误。