在Xcode和IOS项目中,我可以';不要使用常量。获取链接器生成错误

在Xcode和IOS项目中,我可以';不要使用常量。获取链接器生成错误,ios,xcode,cocoa-touch,constants,linker-errors,Ios,Xcode,Cocoa Touch,Constants,Linker Errors,我在Xcode中启动了一个新的iOS项目。添加了两个文件:“constants.h”和“constants.m”,其中包含我在其他文章中看到的内容: 常数.h #import <Foundation/Foundation.h> /// Holds the username for connection to the API extern NSString * const PSUsername_preferences; /// Holds the password for conn

我在Xcode中启动了一个新的iOS项目。添加了两个文件:“constants.h”和“constants.m”,其中包含我在其他文章中看到的内容:

常数.h

#import <Foundation/Foundation.h>

/// Holds the username for connection to the API
extern NSString * const PSUsername_preferences;

/// Holds the password for connection to the API
extern NSString *const PSPassword_preferences; 

///Holds the (hopefully) secure server URL. (Defaults to https://API.SomewhatURL.de)
extern NSString *const PSServername_preferences;
我确信,.m文件是为我的ios目标分配的。 我还确信,该文件是在buildconfigurations-compilesources下添加的

接下来,我将“Constats.h”添加到我的pch文件中:

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import "Constants.h"
#endif
很好。 但是:如果我尝试构建它,我会遇到一个奇怪的链接器错误:

架构i386的未定义符号: “_PSUsername_首选项”,引用自: -AppDelegate.o中的[AppDelegate应用程序WillResignActive:] ld:未找到架构i386的符号 叮当声:错误:链接器命令失败,退出代码为1(使用-v查看调用)

这种情况发生在为这种情况创建的新项目中。我的构建设置似乎还可以,我已经在构建设置下检查了“架构”路径。它们都显示“ArmV7”,但没有显示i386,所以发生了什么


我在
Xcode 4.6.3
上测试了它,也在
Xcode 5
下测试了它。或者添加一些空白以便于阅读

extern NSString * const PSUsername_preferences;
       NSString * const PSUsername_preference

你看到区别了吗?在定义末尾添加字母
s

i386用于模拟器。很好!如果我连接我的设备并在其上启动构建/运行,我将获得架构armv7的未定义符号:“\u PSUsername\u preferences”,引用自:…Argg!我没有看到森林里的树木。。就这样!非常感谢。有趣的是,Xcode自动完成建议使用头声明。只有构建向我展示了这种奇怪的行为。我来自VB.NET角,所以这种构建错误对我来说还是有点奇怪。今天我又学到了一个重要的教训。。
 NSString * value = PSUsername_preferences;
extern NSString * const PSUsername_preferences;
       NSString * const PSUsername_preference