Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 the definition:

struct StructName{  // line 86
 BOOL first; 
 ...
 ...
};

@interface StructName :NSObject  // line 92
BOOL first; // line 93
...
...
@end  // 96

When I go to compile with

gcc main.m  `gnustep-config --objc-flags` -lgnustep-base -o main.bin

I get this message:

Foo/CEFoo.h:93:1: error: redefinition of ‘struct StructName’
Foo/CEFoo.h:86:8: note: originally defined here

I've read this can be caused by either redefining the struct twice, or by recursive import when using include instead of import.

grep -r "struct StructName" *

Only shows one occurrence of the definition.

I've also searched every include statement in the project, and have found no apparent uses of include vs import, or otherwise dual include/imports of CEFoo.h (the file which contains the structure which is being defined / imported more than once).

How can I further hunt down the cause of this? I assume that I am importing it twice -- if I am, is there a way to watch it via verbose or logs defined for the first time?

Any other ideas what I can do to troubleshoot this?

TIA

like image 449
Geremy Avatar asked Jan 27 '26 14:01

Geremy


1 Answers

Defining a class means creating a struct for it, among other things. And you happen to have a struct named 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;
}
like image 153
sidyll Avatar answered Jan 29 '26 06:01

sidyll



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!