错误:在Linux上的Objective-C中进行编译时,重新定义了“ struct StructName”消息
作者:互联网
我正在尝试在Ubuntu 12 Linux上编译Objective-C代码.
main.m看起来像这样:
#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;
}
在CEFoo.h中,我具有以下定义:
struct StructName{ // line 86
BOOL first;
...
...
};
@interface StructName :NSObject // line 92
BOOL first; // line 93
...
...
@end // 96
当我去编译
gcc main.m `gnustep-config --objc-flags` -lgnustep-base -o main.bin
我收到此消息:
Foo/CEFoo.h:93:1: error: redefinition of ‘struct StructName’
Foo/CEFoo.h:86:8: note: originally defined here
我已经读到这可能是由于两次重新定义结构,或者是使用include而不是import时递归导入引起的.
grep -r "struct StructName" *
仅显示一次定义.
我还搜索了项目中的每个include语句,没有发现include vs import的明显用途,或者没有发现CEFoo.h的双重include / imports(该文件包含多次被定义/导入的结构) .
我该如何进一步找出原因呢?我假设我将其导入了两次-如果是的话,是否可以通过首次定义的详细日志来查看它?
还有其他想法可以解决此问题吗?
TIA
解决方法:
定义一个类意味着为其创建一个结构.而且您碰巧有一个与您的类完全相同的结构.例如,在http://ideone.com/7kvFa处检查以下代码“活动”
#import <objc/objc.h>
struct name {};
@interface name
@end
int
main() {
return 0;
}
标签:gnustep,objective-c,redefinition,linux 来源: https://codeday.me/bug/20191101/1981106.html