簡體   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