c – Error : redefinition of ‘struct StructName’ message when compiling in Objective-C on Linux
I’m trying to compile Objective-C code on Ubuntu 12 Linux.
main.m looks like this:
#import <Foundation/Foundation.h>
#import "CEFoo/CEFoo.h"
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (@"hello world");
[pool drain];
return 0;
}
In CEFoo.h, I have this definition:
struct StructName{ // line 86
BOOL first;
...
...
};
@interface StructName :NSObject // line 92
BOOL first; line 93
...
...
@end // 96
When I go to compile
gcc main.m `gnustep-config --objc-flags` -lgnustep-base -o main.bin
I received this message:
Foo/CEFoo.h:93:1: error: redefinition of ‘struct StructName’
Foo/CEFoo.h:86:8: note: originally defined here
I read that this could be caused by redefining the structure twice, or recursive importing when using include instead of import.
grep -r "struct StructName" *
The definition is displayed only once.
I also searched every include statement in the project and didn’t find obvious uses for include vs import, or CEFoo.h’s double include/imports (files containing structures being defined/imported more than once).
How can I further identify the cause of this? I’m assuming I imported twice – if I was, is there a way to observe it through the verbosity or logs defined the first time?
What can I do to fix this? Any other ideas?
TIA
Solution
Defining a class means creating a structure for it, and so on. And you happen to have a structure exactly like your class. For example, check the following code “live” at http://ideone.com/7kvFa
#import <objc/objc.h>
struct name {};
@interface name
@end
int
main() {
return 0;
}