我尝试将 const double NA = 1e-300;
放入 Cocoa-Touch 的头文件中,但 Xcode 不喜欢它。然而,当我在 Cocoa(64 位 MAC)中执行此操作时,它工作得很好。
??????
错误:
<小时/><小时/>Duplicate symbol _NA in /Users/jdl/Library/Developer/Xcode/DerivedData/iExperiment-chcmotcyeolxeacnidtlgofkcihz/Build/Intermediates/iExperiment.build/Debug-iphonesimulator/iExperiment.build/Objects-normal/i386/ViewController.o and /Users/jdl/Library/Developer/Xcode/DerivedData/iExperiment-chcmotcyeolxeacnidtlgofkcihz/Build/Intermediates/iExperiment.build/Debug-iphonesimulator/iExperiment.build/Objects-normal/i386/AppDelegate.o for architecture i386
<小时/>Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang failed with exit code 1
#import <UIKit/UIKit.h>
const double NA = 1e-300; // <------------- Error in Cocoa-Touch but not Cocoa ??
// So where do I put this so it doesn't error out in Cocoa-Touch??
@interface ViewController : UIViewController
{
UITextView *tvText;
}
@end
最佳答案
头文件中定义的常量应如下所示:
__unused static const double NA = 1e-300;
__unused
是为了抑制未使用变量的编译器警告,static
可以防止常量暴露给链接器,这将解决您的问题。
关于objective-c - 在 Cocoa-Touch 的 header 中放置 "const double NA = 1e-300"错误,但在 Cocoa 中则不然?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10438648/