2012-06-19 2 views
1

Visual Studio 2012 RC를 설치하고 간단한 MFC 응용 프로그램을 만들었으므로 MFC 개발과 Visual Studio에 익숙해졌습니다. 현재 애플리케이션은 나를 위해 생성 된 MFC 마법사에 불과합니다.Visual Studio, Visual C++ MFC 응용 프로그램에서 tinyxml2 사용

나는 XML 라이브러리를 통합하기로 결정 했으므로 this one on github을 찾았습니다. ZIP 파일을 소스 코드와 함께 다운로드하여 압축을 푼 다음 Visual Studio에서 솔루션 탐색기로 이동하여 내 솔루션을 선택하고 마우스 오른쪽 버튼으로 클릭 한 다음 "기존 프로젝트"를 선택하십시오. 소스 코드에 대한 프로젝트 파일을 선택하면 솔루션 탐색기 트리에 나타납니다.

코드를 컴파일하고 테스트합니다. 그러나 나는 현재의 솔루션에서 어떻게 사용하는지 잘 모르겠습니다.

는 내 문서에이 코드를 사용하려고 :

내가 프로젝트를 빌드 할 때 나는이 링커 오류가 발생하지만
#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; 
} 

: 내 MFC 선택 솔루션 탐색기에서

------ Build started: Project: GraphApp, Configuration: Debug Win32 ------ 
    GraphAppDoc.cpp 
GraphAppDoc.obj : error LNK2019: unresolved external symbol "public: __thiscall tinyxml2::XMLDocument::XMLDocument(bool)" ([email protected]@@[email protected][email protected]) referenced in function "int __cdecl LoadDocumentFromXML(class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" ([email protected]@[email protected][email protected][email protected][email protected]@@@@@[email protected]@@Z) 
GraphAppDoc.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall tinyxml2::XMLDocument::~XMLDocument(void)" ([email protected]@@[email protected]) referenced in function "int __cdecl LoadDocumentFromXML(class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" ([email protected]@[email protected][email protected][email protected][email protected]@@@@@[email protected]@@Z) 
GraphAppDoc.obj : error LNK2019: unresolved external symbol "public: int __thiscall tinyxml2::XMLDocument::LoadFile(char const *)" ([email protected]@[email protected]@[email protected]) referenced in function "int __cdecl LoadDocumentFromXML(class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" ([email protected]@[email protected][email protected][email protected][email protected]@@@@@[email protected]@@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 앱이 tinyxml 프로젝트에 의존하도록 설정되었는지 확인하고 "빌드 순서"가 올바른지 확인합니다 (tinyxml 먼저). 또한 "References ..."로 이동하여 tinyxml도 추가합니다. 심지어 내 tinyxml의 디버그 디렉토리를 프로젝트 속성의 내 MFC 앱의 포함 경로에도 추가합니다. 내가 놓친 게 뭐야?

답변

8

확인 문서를 완전히 읽지는 못했습니다. 프로젝트에 첨부 된 XML 읽기 here 상태 :

하나의 헤더와 하나의 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 ========== 

을 그럼 내가 클릭 오른쪽 솔루션 탐색기에서 "tinyxml2.cpp"를 선택한 속성에 갔다. "C++"아래 속성에서 나는이 "미리 컴파일 된 헤더를"가서 읽을 수있는 옵션 변경 :

Precompiled Header: Use 

Precompiled Header: Not using precompiled headers 
다음

은 마술 일

에를!

+0

+1 감사합니다. 그것은 나에게도 효과가있다. "미리 컴파일 된 헤더 : 미리 컴파일 된 헤더를 사용하지 않는"설정으로 문제를 해결하는 방법을 알려주실 수 있습니까? –

+1

고맙습니다. 이것으로 오랜 시간 애써 뒀다 –

+0

이 현실을 확인해 주셔서 감사합니다. 나는 CMake ExternalProject와 같은 모든 공상을하기 위해 계속 노력했다. 그리고 그것은 "아주 작다"는 것을 깨닫지 못했다. 두 파일 및 완료. –

관련 문제