I have a file:
#import "OutletsHandler.h"
@implementation OutletsHandler
- (IBAction) pi : (id) sender
{
extern const double PI; // here I try to import PI
[textField setDoubleValue: PI];
}
- (id)init
{
self = [super init];
if (self)
{
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
@end
OutletsHandler.h imports CalculatorScanner.h, this is CalculatorScanner.h:
#import <stdbool.h>
const double PI=3.141592654;
But I get semantic issues:
Command /Developer/usr/bin/clang failed with exit code 1
ld: duplicate symbol _PI in /Users/ramy/Library/Developer/Xcode/DerivedData/Calculator- crcetknqiorefpbjxcrtydequwxf/Build/Intermediates/Calculator.build/Debug/Calculator.build/Objects-normal/x86_64/CalculatorScanner.o and /Users/ramy/Library/Developer/Xcode/DerivedData/Calculator-crcetknqiorefpbjxcrtydequwxf/Build/Intermediates/Calculator.build/Debug/Calculator.build/Objects-normal/x86_64/CalculatorAppDelegate.o for architecture x86_64
What am I doing wrong?
Your problem is that you are defining
PIinCalculatorScanner.h, when you should just be declaring it. To make it compile and link properly, put this inCalculatorScanner.h:and put this in
CalculatorScanner.cpp:But that’s not really the correct solution either, in this case. The correct solution here is to use the standard constant
M_PIinstead of defining your own (less accurate) constant.