0

我创建了一个名为“ObjCWorkAppMath.m”的 NSObject 文件,它包含一些有用的函数,我想在我的 ViewController 文件中使用该类,但 XCode 没有编译我的项目并返回以下错误:

duplicate symbol _OBJC_METACLASS_$_ObjCWorkAppMath in:
    /Users/ctkt/Library/Developer/Xcode/DerivedData/ObjCWorkApp-hgxcjtjhzwxhqxcmxgkpucpfpieq/Build/Intermediates/ObjCWorkApp.build/Debug-iphonesimulator/ObjCWorkApp.build/Objects-normal/i386/ObjCWorkAppMath.o
    /Users/ctkt/Library/Developer/Xcode/DerivedData/ObjCWorkApp-hgxcjtjhzwxhqxcmxgkpucpfpieq/Build/Intermediates/ObjCWorkApp.build/Debug-iphonesimulator/ObjCWorkApp.build/Objects-normal/i386/ObjCWorkAppViewController.o
duplicate symbol _OBJC_CLASS_$_ObjCWorkAppMath in:
    /Users/ctkt/Library/Developer/Xcode/DerivedData/ObjCWorkApp-hgxcjtjhzwxhqxcmxgkpucpfpieq/Build/Intermediates/ObjCWorkApp.build/Debug-iphonesimulator/ObjCWorkApp.build/Objects-normal/i386/ObjCWorkAppMath.o
    /Users/ctkt/Library/Developer/Xcode/DerivedData/ObjCWorkApp-hgxcjtjhzwxhqxcmxgkpucpfpieq/Build/Intermediates/ObjCWorkApp.build/Debug-iphonesimulator/ObjCWorkApp.build/Objects-normal/i386/ObjCWorkAppViewController.o
ld: 2 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我尝试了stackoverflow中的所有解决方案来解决这个错误,但它仍然不起作用或者我做错了......

#import "ObjCWorkAppViewController.h"
#import "ObjCWorkAppMath.m"

@interface ObjCWorkAppViewController ()

@end

@implementation ObjCWorkAppViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

错误在哪里?

4

1 回答 1

2

代替

#import "ObjCWorkAppMath.m"

经过

#import "ObjCWorkAppMath.h"

导入实现文件而不是接口文件会导致类被定义两次:在“ObjCWorkAppMath.m”(它所属的位置)和“ObjCWorkAppViewController.m”(不打算这样做)中。

于 2013-03-23T08:23:35.337 回答