Visual studio 使用TIYXXML2与VisualStudio、Visual C++ MFC应用程序

Visual studio 使用TIYXXML2与VisualStudio、Visual C++ MFC应用程序,visual-studio,visual-c++,Visual Studio,Visual C++,我试图习惯MFC开发和Visual Studio,因此我安装了Visual Studio 2012 RC,并创建了一个简单的MFC应用程序。目前,该应用程序只是为我生成的MFC向导 我决定合并一个XML库,所以我发现。我下载带有源代码的ZIP文件,解压缩它,然后在VisualStudio中转到解决方案资源管理器,选择我的解决方案,右键单击并选择“添加”>“现有项目”。我为源代码选择了项目文件,它显示在我的解决方案资源管理器树中 我测试了代码的编译过程,确实如此。但是,我不太确定如何从我当前的解决

我试图习惯MFC开发和Visual Studio,因此我安装了Visual Studio 2012 RC,并创建了一个简单的MFC应用程序。目前,该应用程序只是为我生成的MFC向导

我决定合并一个XML库,所以我发现。我下载带有源代码的ZIP文件,解压缩它,然后在VisualStudio中转到解决方案资源管理器,选择我的解决方案,右键单击并选择“添加”>“现有项目”。我为源代码选择了项目文件,它显示在我的解决方案资源管理器树中

我测试了代码的编译过程,确实如此。但是,我不太确定如何从我当前的解决方案中使用它

我尝试在我的文档中使用此代码:

#include "../../TinyXML2/leethomason-tinyxml2-a3efec0/tinyxml2.h"

<...snip...>

BOOL LoadDocumentFromXML(const CString& filename) {

    CT2CA pszConvertedAnsiString (filename);
    std::string s(pszConvertedAnsiString);

    tinyxml2::XMLDocument doc(true);
    if (tinyxml2::XML_NO_ERROR != doc.LoadFile(s.c_str())) {
        return FALSE;
    }



    return TRUE;
}
但是,当我尝试构建项目时,出现以下链接器错误:

------ Build started: Project: GraphApp, Configuration: Debug Win32 ------
  GraphAppDoc.cpp
GraphAppDoc.obj : error LNK2019: unresolved external symbol "public: __thiscall tinyxml2::XMLDocument::XMLDocument(bool)" (??0XMLDocument@tinyxml2@@QAE@_N@Z) referenced in function "int __cdecl LoadDocumentFromXML(class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?LoadDocumentFromXML@@YAHABV?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@@Z)
GraphAppDoc.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall tinyxml2::XMLDocument::~XMLDocument(void)" (??1XMLDocument@tinyxml2@@UAE@XZ) referenced in function "int __cdecl LoadDocumentFromXML(class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?LoadDocumentFromXML@@YAHABV?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@@Z)
GraphAppDoc.obj : error LNK2019: unresolved external symbol "public: int __thiscall tinyxml2::XMLDocument::LoadFile(char const *)" (?LoadFile@XMLDocument@tinyxml2@@QAEHPBD@Z) referenced in function "int __cdecl LoadDocumentFromXML(class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?LoadDocumentFromXML@@YAHABV?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@@Z)
C:\Users\Phill\Documents\Visual Studio 2012\Projects\GraphApp\Debug\GraphApp.exe : fatal error LNK1120: 3 unresolved externals
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========

在解决方案资源管理器中,我选择我的MFC应用程序项目,右键单击并选择Dependencies。我确保MFC应用程序被设置为依赖于tinyxml项目,并且我首先确保构建顺序是正确的tinyxml。我也会进入参考资料。。。并在那里添加tinyxml。我甚至还将tinyxml的调试目录添加到我的MFC应用程序的项目属性中的include路径中。请问我遗漏了什么?

好吧,原来我没有完全阅读文档。阅读项目所附的XML说明:

它是一个头文件和一个cpp文件。只需将这些添加到您的项目中 你走吧

所以我做了这个。然后我得到了一些编译器警告:

------ Build started: Project: GraphApp, Configuration: Debug Win32 ------
  tinyxml2.cpp
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(24): warning C4627: '#include "tinyxml2.h"': skipped when looking for precompiled header use
          Add directive to 'stdafx.h' or rebuild precompiled header
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(26): warning C4627: '#include <cstdio>': skipped when looking for precompiled header use
          Add directive to 'stdafx.h' or rebuild precompiled header
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(27): warning C4627: '#include <cstdlib>': skipped when looking for precompiled header use
          Add directive to 'stdafx.h' or rebuild precompiled header
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(28): warning C4627: '#include <new>': skipped when looking for precompiled header use
          Add directive to 'stdafx.h' or rebuild precompiled header
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(29): warning C4627: '#include <cstddef>': skipped when looking for precompiled header use
          Add directive to 'stdafx.h' or rebuild precompiled header
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(1834): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 


然后它神奇地工作了

好吧,原来我没有完全阅读文档。阅读项目所附的XML说明:

它是一个头文件和一个cpp文件。只需将这些添加到您的项目中 你走吧

所以我做了这个。然后我得到了一些编译器警告:

------ Build started: Project: GraphApp, Configuration: Debug Win32 ------
  tinyxml2.cpp
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(24): warning C4627: '#include "tinyxml2.h"': skipped when looking for precompiled header use
          Add directive to 'stdafx.h' or rebuild precompiled header
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(26): warning C4627: '#include <cstdio>': skipped when looking for precompiled header use
          Add directive to 'stdafx.h' or rebuild precompiled header
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(27): warning C4627: '#include <cstdlib>': skipped when looking for precompiled header use
          Add directive to 'stdafx.h' or rebuild precompiled header
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(28): warning C4627: '#include <new>': skipped when looking for precompiled header use
          Add directive to 'stdafx.h' or rebuild precompiled header
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(29): warning C4627: '#include <cstddef>': skipped when looking for precompiled header use
          Add directive to 'stdafx.h' or rebuild precompiled header
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(1834): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 


然后它神奇地工作了

+1谢谢。这对我也有用。你能告诉我如何设置预编译头:不使用预编译头解决问题吗?Thanx很多。很长一段时间以来,我一直在与之抗争,谢谢你的现实检查。我一直试着用奇幻的w/CMake ExternalProject来完成这一切,但没想到它这么小。两个文件,完成了。当我把tinyxml2加入我的项目时,我也疯了。。。您必须右键单击tinyxml2.cpp,选择所有配置,然后选择C/C++->precompiled header->不要使用precompiled header谢谢,您节省了我的时间@Phillumati+1谢谢。这对我也有用。你能告诉我如何设置预编译头:不使用预编译头解决问题吗?Thanx很多。很长一段时间以来,我一直在与之抗争,谢谢你的现实检查。我一直试着用奇幻的w/CMake ExternalProject来完成这一切,但没想到它这么小。两个文件,完成了。当我把tinyxml2加入我的项目时,我也疯了。。。您必须右键单击tinyxml2.cpp,选择所有配置,然后选择C/C++->precompiled header->不要使用precompiled header谢谢,您节省了我的时间@Phillumati
Precompiled Header: Not using precompiled headers