繁体   English   中英

在Xcode和IOS项目中,我不能使用常量。 有链接器构建错误

[英]In Xcode and IOS projects I can't use constants. Got linker build errors

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

Constants.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;

而constants.m:

#import "Constants.h" 

NSString *const PSUsername_preference = @"username_preferences";
NSString *const PSPassword_preference = @"password_preferences";
NSString *const PSServer_preference = @"servername_preferences";

我确信,.m文件被指定为我的ios-target构建。 我也很确定,该文件是在Build Configurations-Compile Sources下添加的。

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

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import "Constants.h"
#endif

我可以在AddDelegate指定其中一个:

 NSString * value = PSUsername_preferences;

尼斯。 但是:如果我尝试构建它,我会得到一个奇怪的链接器错误:

架构i386的未定义符号:“_ PSUsername_preferences”,引用自: - AppDelegate.o中的[AppDelegate applicationWillResignActive:] ld:未找到架构i386的符号clang:错误:链接器命令失败,退出代码为1(使用-v为看调用)

这种情况发生在一个新创建的项目中。 我的构建设置似乎没问题,我已经在Build-Settings下检查了'Architectures'路径。 所有这些都显示'ArmV7'而不是i386,所以最新情况如何?

我在Xcode 4.6.3以及Xcode 5下进行了测试。

逐字阅读你的常名。 或者添加一些空格以便于阅读。

extern NSString * const PSUsername_preferences;
       NSString * const PSUsername_preference

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM