一个Xcode初学者的问题:

这是我第一次使用Xcode 4.6.3。

我试图写一个非常简单的控制台程序,搜索配对的BT设备,并将它们打印到NSLog。

它会生成以下错误:

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

我疯狂地搜索。常见的问题应该是对文件的引用,其中只有头文件被导入,链接器没有找到任何实现(*.m-file)。IOBluetooth库是一个标准框架,就像基础框架一样。

我在上面的陈述中遗漏了什么?

我还尝试为32位机器构建它(构建再次失败)。这显然是一个链接器错误,但我不知道,它与什么有关,除了有一个问题,找到IOBluetoothDevice的实现,在x86和x64架构上,而头文件是从一个标准包含的框架,称为IOBluetooth?

供你参考,我的主要代码是main。m”:

#import <Foundation/Foundation.h>
#import <IOBluetooth/objc/IOBluetoothDevice.h>          // Note the import for bluetooth
#import <IOBluetooth/objc/IOBluetoothDeviceInquiry.h>   // Note the import for bluetooth


int main(int argc, const char * argv[])
{
    @autoreleasepool {
        IOBluetoothDevice *currentDevice;
        NSArray *devices = [ IOBluetoothDevice pairedDevices];


        for (id currentDevice in devices){
          NSLog(@"%i : %@",[ currentDevice classOfDevice ], [ currentDevice name ]);    
        }
    }
    return 0;
}

谢谢你的任何帮助或指点正确的方向。


当前回答

当更新到Xcode 7.1时,你可能会看到这种类型的错误,它不能通过上述任何答案来解决。在我的案例中,其中一个症状是应用程序在设备上而不是在模拟器中运行。您可能会看到大量与您正在使用的几乎所有框架相关的错误。

解决方法其实很简单。你只需要从“框架搜索路径”设置中删除一个条目,在你的TARGETS > Build Settings > Search Paths部分中找到(确保“All”选项卡被选中)

如果您在这里看到主目标或测试目标的另一个条目(除了$(inherited)之外),只需从所有目标中删除错误路径并重新构建。

其他回答

UPD

苹果要求使用arm64架构。在项目中不使用x32库

所以下面的答案不再正确了!


旧的答案

新的Xcode 5.1将架构armv7、armv7s和arm64设置为默认值。

有时错误“build failure”“Undefined symbols for architecture x86_64”可能是由此引起的。因为,一些库(不是苹果的)最初是为x32编译的,不支持x64。

所以你所需要的,就是像这样改变你的项目目标的“架构”

NB。如果你正在使用Cocoapods -你应该为“Pods”目标做同样的事情。

架构x86_64的未定义符号:"_OBJC_CLASS_$_xxx", 引用: yyy.o中的Objc-class-ref

这通常意味着,您从类“yyy”中调用“xxx”(它可能是一个框架或类)。编译器无法定位“xxx”,因此出现此错误。

你需要添加丢失的文件(在本例中是“xxx”),右键单击导航窗口中的项目文件夹,点击“将文件添加到“YourProjectName”选项。

一个弹出窗口将打开Finder中的项目文件。在那里,您可以看到丢失的文件,并将它们添加到您的项目中。不要忘记勾选“需要时复制项目”框。祝你好运! !

I am late to the party but thought of sharing one more scenario where this could happen. I was working on a framework and was distributing it over cocoapods. The framework had both objective c and swift classes and protocols and it was building successfully. While using pod in another framework or project it was giving this error as I forgot to include .m files in podspec. Please include .swtift,.h and .m files in your podspec sources as below: s.source_files = "Projectname/Projectname/**/*.{swift,h,m}"

我希望这能节省别人的时间。

在Xcode 9.0b5中,你可能会遇到这种情况,因为Xcode 9.0b5有一个bug,当你添加源代码时,它不遵守目标设置。你必须在后面手动设置每个文件的目标:

我知道这是一个老问题,但今天得到了同样的错误,上述解决方案都无效。

通过设置选项来修复它:

Project -> Architecture -> Build Active Architecture Only

为Yes

正确地编译和构建项目