Reputation: 193
I created a NSObject file with name "ObjCWorkAppMath.m", it contains some useful functions and I want to use that class in my ViewController file but XCode doesn't compile my project and returns the error below:
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)
I tried all solutions in stackoverflow for this error and it still doesn't work or I can't do it right...
#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
Where is the mistake?
Upvotes: 0
Views: 151
Reputation: 540055
Replace
#import "ObjCWorkAppMath.m"
by
#import "ObjCWorkAppMath.h"
Importing the implementation file instead of the interface file causes the class to be defined twice: In "ObjCWorkAppMath.m" (where it belongs), and in "ObjCWorkAppViewController.m" (which is not intended).
Upvotes: 2