gpt4 book ai didi

objective-c - 编译一个简单的 Objective-C 程序

转载 作者:搜寻专家 更新时间:2023-10-30 19:53:28 24 4
gpt4 key购买 nike

我正在尝试从命令行创建和编译一个简单的 Objective-C 程序。这是代码:

音频.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

我怎样才能编译它?

最佳答案

你还需要编译WavReader

gcc -framework Foundation audio.m WavReader.m -o audio

关于objective-c - 编译一个简单的 Objective-C 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9096151/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com