gpt4 book ai didi

ios - 运行 AVFoundation/AVAudioPlayer 框架时出现 XCode 链接器错误

转载 作者:行者123 更新时间:2023-11-29 11:08:51 25 4
gpt4 key购买 nike

所以我正在尝试一个简单的应用程序来播放一个简单的 mp3,出于某种原因,无论我尝试什么,我都会遇到同样的错误。每当我包含 AVFoundation/AVAudioPlayer 时它就无法运行,它会在我身上崩溃。但是一旦我删除了那个框架,它就可以正常工作了。请帮忙。

这是我收到的错误..

    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

最佳答案

it fails to run whenever i include AVFoundation/AVAudioPlayer

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

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

关于ios - 运行 AVFoundation/AVAudioPlayer 框架时出现 XCode 链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12471237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com