user1635121
user1635121

Reputation: 11

XCode Linker Error When Running an AVFoundation/AVAudioPlayer framework

so im trying out a simple app to play a simple mp3 and for some reason i get the same error no matter what i try. it fails to run whenever i include AVFoundation/AVAudioPlayer it crashes on me. but once i remove that framework, it works fine. please help.

this is the error i recieve..

    ld: warning: ignoring file /Users/nnamdiokeke/Desktop/Play/AVFoundation.framework/AVFoundation, file was built for unsupported file format ( 0xce 0xfa 0xed 0xfe 0x c 0x 0 0x 0 0x 0 0x 9 0x 0 0x 0 0x 0 0x 6 
0x 0 0x 0 0x 0 ) which is not the architecture being linked (i386): /Users/nnamdiokeke/Desktop/Play/AVFoundation.framework/AVFoundation
    Undefined symbols for architecture i386:
      "_OBJC_CLASS_$_AVAudioPlayer", referenced from:
          objc-class-ref in ViewController.o
    ld: symbol(s) not found for architecture i386
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

The code is pasted below.

Header File

//
//  ViewController.h
//  Play
//
//  Created by Nnamdi Okeke on 9/13/12.
//  Copyright (c) 2012 Nnamdi Okeke. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <AVFoundation/AVAudioPlayer.h>

@interface ViewController : UIViewController <AVAudioPlayerDelegate> {

    AVAudioPlayer *song;
    NSURL *songlink;
}

 @property (nonatomic, retain) AVAudioPlayer *song;

-(IBAction)play:(id)sender;

@end

Implementation file

//
//  ViewController.m
//  Play
//
//  Created by Nnamdi Okeke on 9/13/12.
//  Copyright (c) 2012 Nnamdi Okeke. All rights reserved.
//

#import "ViewController.h"
#import <AVFoundation/AVAudioPlayer.h>


@implementation ViewController


- (void)viewDidLoad
{
    songlink = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"A4Hood" ofType:@"mp3"]];
    song = [[AVAudioPlayer alloc] initWithContentsOfURL:songlink error:nil];
    song.delegate = self;
    //[song play];

    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

-(IBAction)play:(id)sender {
    songlink = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"A4Hood" ofType:@"mp3"]];
    song = [[AVAudioPlayer alloc] initWithContentsOfURL:songlink error:nil];
    song.delegate = self;
    [song play];


}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end

Upvotes: 1

Views: 1384

Answers (2)

ettibo
ettibo

Reputation: 83

I'm actually having the same problem, the compiler struggles on this:

#if defined(__cplusplus)
    #define AVF_EXPORT extern "C"
#else
    #define AVF_EXPORT extern
#endif

in AVAudioSettings, this define is used and is not interpreted by the compiler. Can it be because I use some C++ in my app?

After testing, it was the problem. To solve it, create another class where you include AVAudio and do what you have to do with your Audio.

It seems that AVAudio and C++ are not great together. I hope It can help

Upvotes: 1

user529758
user529758

Reputation:

it fails to run whenever i include AVFoundation/AVAudioPlayer

Because inclusion of header files is not enough - you have to link agains AVFoundation.framework, else how would the dynamic loader know where from load the symbols which are not in your binary itself? Thus you have to add the AVFoundation framework to your project in Xcode.

More on why this is necessary here.

Upvotes: 1

Related Questions