3
我想從命令行創建並編譯一個簡單的Objective-C程序。下面是代碼:編譯一個簡單的Objective-C程序
audio.h
#import <Foundation/Foundation.h>
#include <stdlib.h>
#import "WavReader.h"
int main (int argc, const char *argv[])
{
// LOG ARGUMENTS
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (@"Running....");
NSArray *args = [[NSProcessInfo processInfo] arguments];
NSLog(@"Input File %@.", [args objectAtIndex:1]);
NSLog(@"Output File Name %@.", [args objectAtIndex:2]);
WavReader *wavReader = [[WavReader alloc] init];
[wavReader testPrint];
[pool drain];
return 0;
}
WavReader.h
#import <Foundation/Foundation.h>
@interface WavReader : NSObject {
}
- (void) testPrint;
@end
WavReader.m
#import "WavReader.h"
@implementation WavReader
- (void) testPrint
{
NSLog(@"Test print...");
}
@end
,然後我嘗試用
編譯它gcc -framework Foundation audio.m -o audio
,我得到以下錯誤:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_WavReader", referenced from:
objc-class-ref in ccs07gwo.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
我如何能得到這個編譯?