【发布时间】:2014-11-03 09:50:24
【问题描述】:
我刚开始 iOS 编程,正在尝试编译一个简单的代码,但我无法这样做。我收到的错误消息是,
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_Player", referenced from:
objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
现在,我发现了 2 个类似的问题(here 和 here),它们使用与我相同的环境进行编码,并且也面临与我类似的问题。我尝试了他们的解决方案,但没有成功。
当我刚开始使用 iOS 时,我以 tutorial 为指导,并试图运行他们的代码。错误发生在我为播放器变量分配一些值的部分。代码如下。
#import "AppDelegate.h"
#import "Player.h"
#import "PlayersViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate{
NSMutableArray *_players;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
_players = [NSMutableArray arrayWithCapacity:20];
Player *player = [[Player alloc] init];
player.name = @"Bill Evans"; //error will occur here
return YES;
}
我的架构设置如下,
Player.h 和 PlayersViewController.h 的代码与教程中的完全相同。
更新
播放器.h
@interface Player : NSObject
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *game;
@property (nonatomic, assign) int rating;
@end
PlayersViewController.h
#import <UIKit/UIKit.h>
@interface PlayersViewController : UITableViewController
@property (nonatomic, strong) NSMutableArray *players;
@end
我的构建结果
【问题讨论】:
-
听起来您还没有将包含
Player类的源文件添加到Xcode 目标。检查构建日志,看看它是否正在编译。 -
这是否意味着还需要包含 Player 的 .m 文件?我按照教程进行操作,他们提到的只是 .h 文件。我将使用 .h 文件的内容更新我的问题。
-
因此,尽管令人尴尬,但我确实需要包含一个 .m 文件并为我使用“@property”语法声明的那些变量指定“@sysnthesize”语法。
标签: ios8 osx-yosemite xcode6.1