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

发布于 2025-01-01 04:27:09 字数 1295 浏览 1 评论 0原文

我正在尝试从命令行创建并编译一个简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

驱逐舰岛风号 2025-01-08 04:27:09

您还需要编译 WavReader

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

You need to compile the WavReader also

gcc -framework Foundation audio.m WavReader.m -o audio
轻拂→两袖风尘 2025-01-08 04:27:09

编译如下:

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

Compile as follows:

gcc -framework Foundation audio.m WavReader.m -o audio
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文