3

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?

2 Answers 2

7

You need to compile the WavReader also

gcc -framework Foundation audio.m WavReader.m -o audio
Sign up to request clarification or add additional context in comments.

Comments

4

Compile as follows:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.