【问题标题】:Compiling a simple Objective-C program编译一个简单的 Objective-C 程序
【发布时间】:2012-02-01 12:53:20
【问题描述】:

我正在尝试从命令行创建和编译一个简单的 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

如何编译?

【问题讨论】:

    标签: objective-c compiler-construction command-line compilation


    【解决方案1】:

    你还需要编译WavReader

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

    【讨论】:

      【解决方案2】:

      编译如下:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-09-01
        • 2014-02-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多