编译一个简单的 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
我怎样才能得到这个要编译吗?
I'm trying to create and compile a simple Objective-C program from the command line. Here is the code:
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
and then I try to compile it with
gcc -framework Foundation audio.m -o audio
and I get the following error:
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
How can I get this to compile?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还需要编译
WavReader
You need to compile the
WavReader
also编译如下:
Compile as follows: