I added #ifndef..#define..#endif to a file of my project and the compiler fails. As soon as I remove it or put any other name in the define it compiles fine. What could be
Is this macro used as an include guard? If so, it sounds like you're duplicating a name used elsewhere. This is a common problem when people don't think about the scope an include guard must have—you should include much more information in it than just the file name.
Include guard goals:
Bad include guard names (for file "config.h"):
CONFIG_H
_CONFIG_H
, CONFIG__H
, CONFIG_H__
, __CONFIG_H__
, etc.
PROJECT_CONFIG_H
Good include guard names (for file "config.h"):
PATE_20091116_142045
<last name>_<date>_<time>
INCLUDE_GUARD_726F6B522BAA40A0B7F73C380AD37E6B
If you add an #ifndef
for a constant that's already defined, it will always validate to true. You say "the file is declared", but files do not get declared. It is really the constant that you place after #ifndef
that you should be checking. Do a simple search through the whole source tree and double-check in what order your current #define
appears.
And of course: is your code correct? Try with a rubbish name as constant, and place #endif
right after it: if it still errors, you have typos (paste your code, if so). See also this post.
PS: I see that David Thornley was typing similar advice in a comment... sorry if this duplicates info in this thread.