title: compiling xerces-c++ program with Eclipse
body: <p>I am trying to program with xerces-c on windows.</p>
  
  <p>I have successfully built the library and compiled a simple program with success, barebone, with just cmd and notepad. However when I tried to move things to eclipse, things got a bit out of hand.</p>
  
  <p>By simply having a c++ helloworld sample, then including the include files into the project path and build, eclipse is refusing to build the project, generating a lot of error, which I think mostly related to the namespace.</p>
  
  <p>The errors goes as follow:</p>
  
  <pre><code>Info: Internal Builder is used for build
  g++ -I...blablabla -O3 -Wall -c -fmessage-length=0 -o "src\\helloworld.o" "..\\src\\helloworld.cpp" 
  gcc -O3 -Wall -c -fmessage-length=0 -o "src\\includes\\xercesc\\util\\RefStackOf.o" "..\\src\\includes\\xercesc\\util\\RefStackOf.c"
  ..\src\includes\xercesc\util\RefStackOf.c:30:1: error: unknown type name 'XERCES_CPP_NAMESPACE_BEGIN'
   XERCES_CPP_NAMESPACE_BEGIN
  
  ..\src\includes\xercesc\util\RefStackOf.c:35:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before '&lt;' token
   template &lt;class TElem&gt;
        ^
  ..\src\includes\xercesc\util\RefStackOf.c:44:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before '&lt;' token
   template &lt;class TElem&gt; RefStackOf&lt;TElem&gt;::~RefStackOf()
  ..\src\includes\xercesc\util\RefStackOf.c:...
  ...this and that, this and that.... and finally...
  ..\src\includes\xercesc\util\RefStackOf.c:160:1: error: expected '=', ',', ';', 'asm' or '__attribute__' at end of input
   XERCES_CPP_NAMESPACE_END
  </code></pre>
  
  <p>and if I removed the file in error, error will just pop up to another file with the same format, beginning with "I dunno what XERCES_CPP_NAMESPACE_BEGIN means"</p>
  
  <p>I have also tried using another builder, say mingw32-make, but it also generates error in the same format. Only changing the title a bit, and perhaps the files are compiled in different order, starting with this:</p>
  
  <pre><code>mingw32-make all
  'Building file: ../src/includes/xercesc/util/BaseRefVectorOf.c'
  'Invoking: GCC C Compiler'
  gcc -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/includes/xercesc/util/BaseRefVectorOf.d" -MT"src/includes/xercesc/util/BaseRefVectorOf.o" -o "src/includes/xercesc/util/BaseRefVectorOf.o" "../src/includes/xercesc/util/BaseRefVectorOf.c"
  ../src/includes/xercesc/util/BaseRefVectorOf.c:24:1: error: unknown type name 'XERCES_CPP_NAMESPACE_BEGIN'
  XERCES_CPP_NAMESPACE_BEGIN
  </code></pre>
  
  <p>I am guessing that the build program does not understand how to replace the</p>
  
  <p>XERCES_CPP_NAMESPACE_BEGIN, with</p>
  
  <p>namespace XERCES_CPP_NAMESPACE { }<br>
  namespace xercesc = XERCES_CPP_NAMESPACE;</p>
  
  <p>But I don't know of a way to teach the builder how to do this, nor I am sure if I have compiled the library in the correct way.</p>
  
  <p>Can someone point me in some direction as to how to solve this? I can compile a simple program by just using cmd, so certainly I should be able to do it in Eclipse.</p>
  
  <p>background:</p>
  
  <ul>
  <li>OS: Windows 8 64bit</li>
  <li>compiler: mingw-w64 5.3.0 posix-seh-rev0</li>
  <li>lib compiled with msys</li>
  <li>lib compilation command:</li>
  <li>./configure --prefix=/specific-location --host=x86_64-w64-mingw32 --enable-netaccessor-winsock --enable-transcoder-windows --disable-pretty-make</li>
  <li>make LDFLAGS=-no-undefined</li>
  <li>make check</li>
  <li>make install</li>
  </ul>
  
  <p>cmd compilation command: g++ -Llib -Iinclude -o b.exe test.cpp</p>
  
  <p>so you can see that I have also included every xerces-c header into the compiler with the -Iinclude command, so I reckon that g++ should not produce error when invoked in Eclipse, not that I know anything if its gcc.</p>
  
  <p>simple program that ran when simply compiled with cmd:</p>
  
  <pre><code>//test.cpp
  #include &lt;xercesc/parsers/XercesDOMParser.hpp&gt;
  #include &lt;xercesc/dom/DOM.hpp&gt;
  #include &lt;xercesc/sax/HandlerBase.hpp&gt;
  #include &lt;xercesc/util/XMLString.hpp&gt;
  #include &lt;xercesc/util/PlatformUtils.hpp&gt;
  
  #include &lt;iostream&gt;
  
  using namespace std;
  using namespace xercesc;
  
  int main (int argc, char* args[]) {
  
      try {
          XMLPlatformUtils::Initialize();
      }
      catch (const XMLException&amp; toCatch) {
          char* message = XMLString::transcode(toCatch.getMessage());
          cout &lt;&lt; "Error during initialization! :\n"
               &lt;&lt; message &lt;&lt; "\n";
          XMLString::release(&amp;message);
          return 1;
      }
  
      XercesDOMParser* parser = new XercesDOMParser();
      parser-&gt;setValidationScheme(XercesDOMParser::Val_Always);
      parser-&gt;setDoNamespaces(true);    // optional
  
      ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
      parser-&gt;setErrorHandler(errHandler);
  
      char* xmlFile = "x1.xml";
  
      try {
          parser-&gt;parse(xmlFile);
          DOMDocument* xmlDoc = parser-&gt;getDocument();
          DOMElement* elementRoot = xmlDoc-&gt;getDocumentElement();
          if( !elementRoot ) throw(std::runtime_error( "empty XML document" ));
          DOMNodeList* children = elementRoot-&gt;getChildNodes();
          const  XMLSize_t nodeCount = children-&gt;getLength();
          cout &lt;&lt; nodeCount &lt;&lt; " nodes\n";
      }
      catch (const XMLException&amp; toCatch) {
          char* message = XMLString::transcode(toCatch.getMessage());
          cout &lt;&lt; "Exception message is: \n"
               &lt;&lt; message &lt;&lt; "\n";
          XMLString::release(&amp;message);
          return -1;
      }
      catch (...) {
          cout &lt;&lt; "Unexpected Exception \n" ;
          return -1;
      }
  
      delete parser;
      delete errHandler;
      return 0;
  }
  </code></pre>
  
  <p>@EDIT</p>
  
  <p>After further investigation, it seems that the XERCES_CPP_NAMESPACE_BEGIN is handled in preprocessor, but its only defined in the file <code>util/XercesDefs.hpp</code></p>
  
  <p>In the files with compilation error, they always begin with</p>
  
  <pre><code>#if defined(XERCES_TMPLSINC)
  #include &lt;xercesc/util/RefStackOf.hpp&gt; //or include anything else blablabla, which ultimately leads to XercesDefs.hpp
  #endif
  </code></pre>
  
  <p>I searched through the entire build directory for the string XERCES_TMPLSINC, it was contained in 44 .c or .hpp files, but everyone of them is <code>#if !defined(XERCES_TMPLSINC)</code> &lt;===== WRONGWRONG , so like XERCES_TMPLSINC was never actually defined.</p>
  
  <p>According to some <a href="http://apache-xml-project.6118.n7.nabble.com/compiler-defines-xercesc-2-8-td40201.html" rel="nofollow">forum post</a>, XERCES_TMPLSINC was required for some old c compilers, so does anyone know how to fix this in my build? how could I define XERCES_TMPLSINC in the project? I have tried adding <code>#define XERCES_TMPLSINC</code> to the helloworld file but it still does not work.</p>
  
  <p>@EDIT</p>
  
  <p>my bad, actually all the .c files contained <code>#if defined(XERCES_TMPLSINC)</code> and all hpp files were <code>#if !defined(XERCES_TMPLSINC)</code>, this definitely seems a c and c++ thing?</p>