User forums > Help
Mingw/C::B compiler ignoring header wrappers to prevent multiple inclusion?
(1/1)
DJMaze:
C::B 1.0rc2
save the following code as test.h
--- Code: ---#ifndef test_h
#define test_h
#warning test.h included
#include test.h
#endif
--- End code ---
Now include this file somewhere in your project and compile your project.
As you can see the file gets included endlessly because it ignores the #ifndef wrapper.
Looking at the generated makefile it uses single commands for each .cxx file as well.
Isn't there a way to compile in one go to prevent the multiple inclusions?
TDragon:
No issues for me, test.h is only included once both from a command line test and as part of a C::B project.
Why aren't you using a nightly build of C::B?
thomas:
I don't know what exactly you are doing there, but if #ifndef and #define refer to the same macro, then this certainly works fine. Very likely, you have a typo in your sources.
The code which you posted compiles fine, as is to be expected of course. This is the most basic preprocessor functionality, and it is used in every system header and every project (including Code::Blocks itself).
DJMaze:
maybe the sample wasn't real enough since the error actualy occures when i have 2 header files like:
/test.h
--- Code: ---#ifndef test_h
#define test_h
#warning test.h included
#include "h/test2.h"
#endif
--- End code ---
/h/test2.h
--- Code: ---#ifndef test2_h
#define test2_h
#warning test2.h included
#include "../test.h"
#endif
--- End code ---
Will further investigate this when i have get the nightly build.
thomas:
Again, this works fine.
Header guards are one of the most basic techniques, and it is really pointless to discuss whether they work or not. They do.
If that did not work, then nobody would be able to compile anything. You cannot even include stdio.h if header guards don't work...
Navigation
[0] Message Index
Go to full version