iphone - "Apple Mach-O linker command failed with exit code 1"

标签 iphone ios multithreading

我正在尝试实现 SVProgressHUD 事件指示器。我将这些类复制到我的项目并将以下代码添加到我的 appDelegate 但无法弄清楚它崩溃的原因。

我发现他们出现以下错误,但我不确定去哪里修复它:

Undefined symbols for architecture i386:
"_OBJC_CLASS_$_SVProgressHUD", referenced from:
objc-class-ref in QuotesAppDelegate.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

代码如下:

#import "SVProgressHUD.h"

@implementation QuotesAppDelegate


- (void)startLoading
{
    //call this in your app delegate instead of setting window.rootViewController to your main view controller
    //you can show a UIActivityIndiocatorView here or something if you like
    [SVProgressHUD show];
    [self performSelectorInBackground:@selector(loadInBackground) withObject:nil];
}

- (void)loadInBackground
{
    //do your loading here
    //this is in the background, so don't try to access any UI elements
    [self populateFromDatabase];

    [SVProgressHUD dismiss];

    [self performSelectorOnMainThread:@selector(finishedLoading) withObject:nil waitUntilDone:NO];
}

- (void)finishedLoading
{
    //back on the main thread now, it's safe to show your view controller
    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];
}


- (void)applicationDidFinishLaunching:(UIApplication *)application {

[self copyDatabaseIfNeeded];

    [self startLoading];

}

最佳答案

编辑

我提供的答案(参见我的原始答案)仅解决了问题,但不是正确的解决方案。对于正确的解决方案,请参阅 Jim 答案

It sounds like SVProgressHUD.m isn't enabled for your target. Click on it in the project navigator in the left-hand pane, then look in the file inspector in the right-hand pane to make sure there's a tick next to the target you are building.

Parth Bhatt链接。

为了完整性

稍微试验一下,我发现当您在项目中拖放文件或目录时,Xcode (4.3.1) 会要求您选择正确的选项以将这些文件或目录添加到您的项目中。确保选中“添加到目标”选项。

如果您错过了勾选该选项,您需要按照以下步骤操作:

  1. 选择您的项目名称
  2. 选择目标
  3. 选择构建阶段
  4. 在 Compile Sources 部分添加 .m 类

我原来的回答

如果您将这些类拖到项目中,则可能是问题所在。

为避免该编译错误,请改用“将文件添加到您的项目名称”。

假设您的桌面上有一个目录,其中包含名为“SVProgressHUD”的 .h 和 .m 文件。

现在你必须:

  1. 删除以前的文件(.h 和 .m)
  2. 在您的项目中单击鼠标右键
  3. 选择“SVProgressHUD”目录和“Add Files to YourProjectName”(选择以下复选框选项:Destination Copy items... and Folders Create groups for any。 ..)

希望对您有所帮助。

关于iphone - "Apple Mach-O linker command failed with exit code 1",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9809477/

相关文章:

iphone - 是否可以使用 NSLog 语句提交 iPhone 应用程序二进制文件?

iphone - 如何在没有浏览器嗅探的情况下将样式表仅应用于 iPhone(而不是 IE)?

iphone - iPhone/iTunes Connect-是否可以自动创建应用并为其填写元数据?

ios - 除了自动收缩之外,还有没有办法让长字符串换行?

ios - 在 iOS 中创建多维数组

ios - 适用于 Android 的 Firebase 推送通知,但仅适用于 iOS 的 Firebase 控制台

iphone - 获取 NULL 值解析 JSON 字符串

multithreading - 基于静态状态的回收与基于时代的回收

c++ - 通过指向实例的静态指针访问成员变量

c - glibc 的 fprintf() 实现是线程安全的吗?