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).