Ciao a tutti, premetto che ora sto cominciando ad approfondire il c++ e già mi trovo difronte ad un problema.
Devo utilizzare il parser xerces c++ e dopo averlo decompresso e aver aggiornato l'elenco directory per i file di inclusione di Visual c++ 2008 express edition ho provato a compilare ed eseguire il seguente file incluso in un progetto di Visual c++ 2008 ee del tipo Progetto Console Win32:
codice:
// prova1.cpp : definisce il punto di ingresso dell'applicazione console.
//
#include "stdafx.h"
#include <iostream>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
#if defined(XERCES_NEW_IOSTREAMS)
#include <iostream>
#else
#include <iostream.h>
#endif
XERCES_CPP_NAMESPACE_USE
// ---------------------------------------------------------------------------
// This is a simple class that lets us do easy (though not terribly efficient)
// trancoding of char* data to XMLCh data.
// ---------------------------------------------------------------------------
class XStr
{
public :
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
XStr(const char* const toTranscode)
{
// Call the private transcoding method
fUnicodeForm = XMLString::transcode(toTranscode);
}
~XStr()
{
XMLString::release(&fUnicodeForm);
}
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
const XMLCh* unicodeForm() const
{
return fUnicodeForm;
}
private :
// -----------------------------------------------------------------------
// Private data members
//
// fUnicodeForm
// This is the Unicode XMLCh format of the string.
// -----------------------------------------------------------------------
XMLCh* fUnicodeForm;
};
#define X(str) XStr(str).unicodeForm()
// ---------------------------------------------------------------------------
// main
// ---------------------------------------------------------------------------
int main(int argC, char*[])
{
// Initialize the XML4C2 system.
try
{
XMLPlatformUtils::Initialize();
}
catch(const XMLException& toCatch)
{
char *pMsg = XMLString::transcode(toCatch.getMessage());
XERCES_STD_QUALIFIER cerr << "Error during Xerces-c Initialization.\n"
<< " Exception message:"
<< pMsg;
XMLString::release(&pMsg);
return 1;
}
// Watch for special case help request
int errorCode = 0;
if (argC > 1)
{
XERCES_STD_QUALIFIER cout << "\nUsage:\n"
" CreateDOMDocument\n\n"
"This program creates a new DOM document from scratch in memory.\n"
"It then prints the count of elements in the tree.\n"
<< XERCES_STD_QUALIFIER endl;
errorCode = 1;
}
if(errorCode) {
XMLPlatformUtils::Terminate();
return errorCode;
}
{
// Nest entire test in an inner block.
// The tree we create below is the same that the XercesDOMParser would
// have created, except that no whitespace text nodes would be created.
// <company>
// <product>Xerces-C</product>
// <category idea='great'>XML Parsing Tools</category>
// <developedBy>Apache Software Foundation</developedBy>
// </company>
DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(X("Core"));
if (impl != NULL)
{
try
{
DOMDocument* doc = impl->createDocument(
0, // root element namespace URI.
X("company"), // root element name
0); // document type object (DTD).
DOMElement* rootElem = doc->getDocumentElement();
DOMElement* prodElem = doc->createElement(X("product"));
rootElem->appendChild(prodElem);
DOMText* prodDataVal = doc->createTextNode(X("Xerces-C"));
prodElem->appendChild(prodDataVal);
DOMElement* catElem = doc->createElement(X("category"));
rootElem->appendChild(catElem);
catElem->setAttribute(X("idea"), X("great"));
DOMText* catDataVal = doc->createTextNode(X("XML Parsing Tools"));
catElem->appendChild(catDataVal);
DOMElement* devByElem = doc->createElement(X("developedBy"));
rootElem->appendChild(devByElem);
DOMText* devByDataVal = doc->createTextNode(X("Apache Software Foundation"));
devByElem->appendChild(devByDataVal);
//
// Now count the number of elements in the above DOM tree.
//
const XMLSize_t elementCount = doc->getElementsByTagName(X("*"))->getLength();
XERCES_STD_QUALIFIER cout << "The tree just created contains: " << elementCount
<< " elements." << XERCES_STD_QUALIFIER endl;
doc->release();
}
catch (const OutOfMemoryException&)
{
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
errorCode = 5;
}
catch (const DOMException& e)
{
XERCES_STD_QUALIFIER cerr << "DOMException code is: " << e.code << XERCES_STD_QUALIFIER endl;
errorCode = 2;
}
catch (...)
{
XERCES_STD_QUALIFIER cerr << "An error occurred creating the document" << XERCES_STD_QUALIFIER endl;
errorCode = 3;
}
} // (inpl != NULL)
else
{
XERCES_STD_QUALIFIER cerr << "Requested implementation is not supported" << XERCES_STD_QUALIFIER endl;
errorCode = 4;
}
}
XMLPlatformUtils::Terminate();
return errorCode;
}
La compilazione va a buon termine, ma quando eseguo il debug mi da i seguenti errori:
Compilazione in corso...
prova1.cpp
Collegamento in corso...
prova1.obj : error LNK2019: riferimento al simbolo esterno "__declspec(dllimport) public: static class xercesc_3_1:OMImplementation * __cdecl xercesc_3_1:OMImplementationRegistry::getDOMImplementation(wch ar_t const *)" (__imp_?getDOMImplementation@DOMImplementationRegi stry@xercesc_3_1@@SAPAVDOMImplementation@2@PB_W@Z) non risolto nella funzione __catch$_main$0
prova1.obj : error LNK2019: riferimento al simbolo esterno "__declspec(dllimport) public: static void __cdecl xercesc_3_1::XMLPlatformUtils::Terminate(void)" (__imp_?Terminate@XMLPlatformUtils@xercesc_3_1@@SA XXZ) non risolto nella funzione __catch$_main$0
prova1.obj : error LNK2019: riferimento al simbolo esterno "__declspec(dllimport) public: static void __cdecl xercesc_3_1::XMLString::release(char * *,class xercesc_3_1::MemoryManager * const)" (__imp_?release@XMLString@xercesc_3_1@@SAXPAPADQAV MemoryManager@2@@Z) non risolto nella funzione __catch$_main$0
prova1.obj : error LNK2019: riferimento al simbolo esterno "__declspec(dllimport) public: static char * __cdecl xercesc_3_1::XMLString::transcode(wchar_t const * const,class xercesc_3_1::MemoryManager * const)" (__imp_?transcode@XMLString@xercesc_3_1@@SAPADQB_W QAVMemoryManager@2@@Z) non risolto nella funzione __catch$_main$0
prova1.obj : error LNK2019: riferimento al simbolo esterno "__declspec(dllimport) public: wchar_t const * __thiscall xercesc_3_1::XMLException::getMessage(void)const " (__imp_?getMessage@XMLException@xercesc_3_1@@QBEPB _WXZ) non risolto nella funzione __catch$_main$0
prova1.obj : error LNK2001: simbolo esterno "__declspec(dllimport) public: static class xercesc_3_1::MemoryManager * xercesc_3_1::XMLPlatformUtils::fgMemoryManager" (__imp_?fgMemoryManager@XMLPlatformUtils@xercesc_3 _1@@2PAVMemoryManager@2@A) non risolto
prova1.obj : error LNK2019: riferimento al simbolo esterno "__declspec(dllimport) public: static void __cdecl xercesc_3_1::XMLPlatformUtils::Initialize(char const * const,char const * const,class xercesc_3_1::PanicHandler * const,class xercesc_3_1::MemoryManager * const)" (__imp_?Initialize@XMLPlatformUtils@xercesc_3_1@@S AXQBD0QAVPanicHandler@2@QAVMemoryManager@2@@Z) non risolto nella funzione _main
prova1.obj : error LNK2001: simbolo esterno "__declspec(dllimport) public: static char const * const xercesc_3_1::XMLUni::fgXercescDefaultLocale" (__imp_?fgXercescDefaultLocale@XMLUni@xercesc_3_1@ @2QBDB) non risolto
prova1.obj : error LNK2019: riferimento al simbolo esterno "__declspec(dllimport) public: static wchar_t * __cdecl xercesc_3_1::XMLString::transcode(char const * const,class xercesc_3_1::MemoryManager * const)" (__imp_?transcode@XMLString@xercesc_3_1@@SAPA_WQBD QAVMemoryManager@2@@Z) non risolto nella funzione "public: __thiscall XStr::XStr(char const * const)" (??0XStr@@QAE@QBD@Z)
prova1.obj : error LNK2019: riferimento al simbolo esterno "__declspec(dllimport) public: static void __cdecl xercesc_3_1::XMLString::release(wchar_t * *,class xercesc_3_1::MemoryManager * const)" (__imp_?release@XMLString@xercesc_3_1@@SAXPAPA_WQA VMemoryManager@2@@Z) non risolto nella funzione "public: __thiscall XStr::~XStr(void)" (??1XStr@@QAE@XZ)
C:\Documents and Settings\Alessandra\Documenti\Visual Studio 2008\Projects\prova1\Debug\prova1.exe : fatal error LNK1120: 10 esterni non risolti
A questo punto ho seguito una procedura in cui mi diceva di aggiungere al file stdafx.h le seguenti linee di codice:
codice:
template class __declspec(dllimport) CStringT<TCHAR, StrTraitMFC<TCHAR, ChTraitsCRT<TCHAR> > >
template class __declspec(dllimport) CSimpleStringT<TCHAR>
ma quando eseguo il debug mi da il seguente errore:
stdafx.h(14) : error C2059: errore di sintassi:
Qualcuno ha qualche suggerimento???
Grazie!!!