2012-09-18 63 views
0

所以即时尝试一个简单的应用程序来播放一个简单的MP3,并由于某种原因,我得到同样的错误,无论我尝试。 无法运行,只要我包括AVFoundation/AVAudioPlayer它崩溃在我身上。但一旦我删除该框架,它工作正常。 请帮忙。运行AVFoundation/AVAudioPlayer框架时出现XCode链接器错误

这是我收到错误..

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) 

的代码如下粘贴。

头文件

// 
// 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 

实现文件

// 
// 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 
+0

您是否在项目中添加了AVFoundation framwork? –

+0

你在你的项目中正确添加avfoundation framwork? –

+0

对两者都是。框架工作在我的项目中。 @RomitMewada ..我需要以任何不同于上述代码的方式以编程方式实现或实现框架吗? – user1635121

回答

0

它无法运行每当我包括AVFoundation/AVAudioPlayer

由于包含头文件是不够的 - 你必须再次链接AV Foundation.framework,否则动态加载器如何知道从哪里载入不在二进制文件中的符号?因此,您必须将AVFoundation框架添加到Xcode中的项目中。

更多关于为什么这是必要的here

+0

嗨。我已经将框架添加到我的项目中,但仍然遇到同样的问题。是否需要以与上述代码不同的方式以编程方式实现或导入框架? – user1635121

+0

@userxxx不,添加框架应该足够了。你错过了别的... – 2012-09-18 09:46:13

+0

你能帮我找到什么吗? – user1635121

0

实际上,我有同样的问题, 这个编译器的斗争:用于

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

,这个定义并没有被编译器解释。 难道是因为我在我的应用程序中使用了一些C++吗?

经过测试,这是问题所在。 要解决这个问题,请创建另一个包含AVAudio的课程,并完成与音频相关的操作。

看来,AVAudio和C++并不是很棒。 我希望它可以帮助