Menu

Error compiling tinyxml

2005-12-17
2013-05-20
  • Joachim Weber

    Joachim Weber - 2005-12-17

    In my current project I implement a scripting language, which interfaces to C++ via library files that contain function definition. I wrote my library file in xml and would like to import it using tinyxml. However, if I add the tinyxml files to my project and include the "tinyxml.h" file I get over 100 errors saying things like:
    "c:\programme\microsoft platform sdk\include\windef.h(152) : error C2143: syntax error : missing ';' before 'constant'"
    Why do these errors occur?

     
    • Yves Berquin

      Yves Berquin - 2005-12-18

      What compiler are you using ?

       
    • Joachim Weber

      Joachim Weber - 2005-12-18

      Visual C++ Express (2005)
      In my other project tinyxml compiled without any errors, using the same compiler.
      Could the fact that I use lex and yacc in this project be related to this?

       
      • Ellers

        Ellers - 2005-12-18

        Without seeing the exact line that you're talking about (c:\programme\microsoft platform sdk\include\windef.h line 152) I'm guessing you've got the #include order wrong. The general rule is to make sure that all the windows stuff comes first.

        Failing that, post a copy of the line from your windef.h.

         
    • Joachim Weber

      Joachim Weber - 2005-12-18

      Well, my project does not include any of the windows headers, since it is a console application.
      I get errors in windef.h, winnt.h and winbase.h, all of them related to typedefs like:
      typedef unsigned long       DWORD;
      and the usage of types like DWORD and BOOL and so on.

       
    • Ellers

      Ellers - 2005-12-18

      Windef.h etc *are* Windows headers.
      Why are they being included?
      Are you sure they're first in the #include order?

      Either way, if you have other projects that compile with this compiler in your environment, but this one doesn't, then this particular problem is specific to the way your code is organised in this project (e.g. #include order), and has nothing to do with TinyXml.

       
    • Joachim Weber

      Joachim Weber - 2005-12-18

      Of course windef.h etc *are* windows headers, but I did not include them. I have absolutely no idea, why visual c++ includes them.
      And besides, the same source code can be compiled usign devc++ without generating any errors.

       
      • Ellers

        Ellers - 2005-12-18

        :) VisualC++ isn't doing it for fun. Something in your code #include's them. One way to solve this is to try #include'ing the file 'first' in your project (often easiest with the precompiled header approach), and it will probably solve things.

        Failing that, you can turn on the preprocessor compile mode, that will show you exactly what includes windef.h etc. Unfortunately I don't know how to do that with VC++.

        Not sure what you mean by "the same source code can be compiled usign devc++". Presumably you mean the exact same project; in which case what is "devc++" ?

        Have you tried systematically "#ifdef 0"'ing out blocks of code until the error goes away? That way isolating whatever piece of code is causing the problem?

         
    • Joachim Weber

      Joachim Weber - 2005-12-18

      Yes, I meant the exact same project ;) And by devc++ I referred to the Bloodshed DevCpp IDE which utilizes the GNU Compiler Collection.
      And including the files myself (before including tinyxml.h) gave me even more errors.

       
    • Joachim Weber

      Joachim Weber - 2005-12-18

      I do not know what you mean by "turning on the preprocessor compile mode" but if I let the compiler generate preprocessed source files a linker error is generated, saying that some file cannot be opened.
      But looking at the intermediate files, there does not seem to be any reference to windef.h

       
    • Joachim Weber

      Joachim Weber - 2005-12-18

      Ah, I found a useful compiler option. Namely, the "show includes" switch :)
      Having a look at the includes leads me to the following conclusion:
      windef.h is included by windows.h, which is in turn included by tinyxml.h

       
    • Ellers

      Ellers - 2005-12-18

      'show includes' - excellent. Thats the sort of thing I meant, more or less.

      The fact that it is included in tinyxml.h and compiles in other envs means that windows.h is not the problem - but pretty much guarantees that there is something wrong with your specific project.

      I still think this is a plain old C++ question, not to do with TinyXml at all. Still, the only thing I can suggest is to build a new small project that reproduces the error and post a zip of the files.

      HTH

       
    • Joachim Weber

      Joachim Weber - 2005-12-18

      Well, here's some funny facts:

      1) A console application including nothing but the tinyxml files compiles without errors

      2) My project does compile without errors, if I switch from Debug to Release mode

       
    • Joachim Weber

      Joachim Weber - 2005-12-18

      Additionally if I change this piece of code from tinyxml.h:
      #if defined( DEBUG ) && defined( _MSC_VER )
      #include <windows.h>
      #define TIXML_LOG OutputDebugString
      #else
      #define TIXML_LOG printf
      #endif

      into this:
      #if defined( DEBUG ) && defined( _MSC_VER )
      //#include <windows.h>
      #define TIXML_LOG OutputDebugString
      #else
      #define TIXML_LOG printf
      #endif

      it compiles in debug mode as well

       
    • Ellers

      Ellers - 2005-12-18

      You've got two broad choices then.

      Item (1) shows that something else in your code in the original project is what is introducing the error. You could try introducing #includes (or whatever) one by one until the error shows up.

      The "//#include <windows.h>" modification gives you the option to keep working, rather than finding the real problem.

      Easy :)

       
    • Joachim Weber

      Joachim Weber - 2005-12-18

      Actually including <windows.h> instead of tinyxml.h will generate the same errors...
      I suppose this has got something to do with visual c++ console projects...

       
    • Joachim Weber

      Joachim Weber - 2005-12-18

      I found out that excluding the file parse.cpp from my project lets the project compile. Of course, I do get some linker errors because the functions in parse.cpp are missing.
      Therefore the error must be somewhere in parse.cpp. Parse.cpp is a parser that was generated by yacc and I have never touched the file.
      But what part of a yacc parser could generate these errors?

       
    • Ellers

      Ellers - 2005-12-18

      Its good that you've narrowed it to one file.

      I can only suggest continuing the pattern: use "#if NOT_DEF....#endif" around the whole file, and compile it. It should work fine. Then move the start #if NOT_DEF down a certain amount, and keep going until it breaks.

       
    • Joachim Weber

      Joachim Weber - 2005-12-18

      I think I found the error. yacc uses #define to define numerical constants that represent the tokens retrieved from lex.
      And since my scripting language has a BOOL datatype, there is a #define BOOL 1 within the file. This will of course corrupt windows typedefs...

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.