得到“架构i386的未定义符号:”试图得到常量

时间:2012-10-09 21:47:45

标签: ios

我知道有很多类似的问题,我没有找到我的案例:

我有:

#import <Foundation/Foundation.h>

@interface BSConstants : NSObject

extern NSString* const DB_COLUMN_NAME;
extern NSString* const DB_COLUMN_PRICE;
extern NSString* const DB_COLUMN_DESCRIPTION;
extern NSString* const DB_COLUMN_ICON;     
extern NSString* const DB_COLUMN_IMAGE; 

@end

#import "BSConstants.h"

@implementation BSConstants

NSString* const DB_COLUMN_NAME              = @"name";
NSString* const DB_COLUMN_PRICE             = @"price";
NSString* const DB_COLUMN_DESCRIPTION       = @"description";
NSString* const DB_COLUMN_ICON              = @"icon";
NSString* const DB_COLUMN_IMAGE             = @"image";

@end

当我尝试构建我的项目时,我得到了:

Undefined symbols for architecture i386:
  "_CONST_SHOPPING_CART_PURCHASE_MAX_SIZE", referenced from:
      -[BSShoppingCartViewController onBuyButtonPressed:] in BSShoppingCartViewController.o
  "_NAME_CREATED_FILE", referenced from:
      -[BSImageSaver saveImageAsPng:] in BSImageSaver.o
  "_NAME_DOWNLOADS_FOLDER", referenced from:
      -[BSImageSaver saveImageAsPng:] in BSImageSaver.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

尝试访问:

#import "BSConstants.h"

 ... DB_COLUMN_NAME

2 个答案:

答案 0 :(得分:9)

我发现了错误 - 我在.h和.m文件中有不同的常量名称。

答案 1 :(得分:1)

首先尝试更改此

extern NSString* const DB_COLUMN_NAME;extern const NSString* DB_COLUMN_NAME;

相同
NSString* const DB_COLUMN_NAME              = @"name";

  

const NSString * DB_COLUMN_NAME = @&#34; name&#34 ;;

另请参阅如何访问这些内容。