"Apple Mach-O链接器命令失败,退出代码为1"

jro*_*yce 9 iphone multithreading ios

我正在尝试实现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) 
Run Code Online (Sandbox Code Playgroud)

这是代码:

#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];

}
Run Code Online (Sandbox Code Playgroud)

Lor*_*o B 16

编辑

我提供的答案(请参阅我的原始答案)仅解决了问题,但这不是正确的解决方案.对于正确的解决方案看吉姆回答

听起来SVProgressHUD.m没有为您的目标启用.在左侧窗格的项目导航器中单击它,然后查看右侧窗格中的文件检查器,以确保您正在构建的目标旁边有一个勾号.

Parth Bhatt链接.

为了完整起见

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

如果您错过了检查该选项,则需要执行以下步骤:

  1. 选择YourProjectName
  2. 选择TARGETS
  3. 选择Build Phases
  4. 在Compile Sources部分添加.m类

我原来的答案

如果您在项目中拖动这些类,则可能是问题所在.

要避免编译错误,请使用"将文件添加到YourProjectName".

假设您的桌面中包含名为"SVProgressHUD"的.h和.m文件的目录.

现在你必须:

  1. 删除以前的文件(.h和.m)
  2. 单击右键单击项目
  3. 使用"将文件添加到YourProjectName"选择"SVProgressHUD"目录(选择以下复选框选项:目标复制项目...和文件夹为任何...创建组)

希望能帮助到你.