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?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
:) 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?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
'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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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 :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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?
What compiler are you using ?
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?
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.
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.
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.
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.
:) 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?
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.
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
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
'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
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
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
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 :)
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...
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?
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.
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...