一个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;
}

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


当前回答

I have found this can also occur if you drag a folder with Objective-C files into your project. If that folder appears blue I think it indicates its not properly linked. You can verify this (if you use version control) because whenever you add new files the pbxproj file should update with links to those new files. However you may find that after you added a folder that the pbxproj file did not change (and hence there is a linking error). So you will get auto-complete working and it will find the classes you imported, but when it goes to actually build the image it fails with this error code.

解决方案是不添加文件夹,而是添加文件。这样做,您应该会看到pbxproj文件更新,它应该会修复这个错误。

这还假定您已经完成了上面建议的操作,并正确链接了所有正确的框架。

其他回答

在我的例子中,我构建了一个自定义框架,部署目标设置为9.1,但我的应用程序的部署目标更低,它支持8.1。最小化自定义框架部署目标解决了我的问题。

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}"

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

帮助我的是在抛出错误的项目中向我的/podspec添加s.static_framework = true。

UPD

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

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


旧的答案

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

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

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

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

架构x86_64的未定义符号

我在使用CocoaPods时遇到过这个问题,它没有特定的版本,这就是为什么在pod更新后它下载了最新版本,其中包括一些突破性的变化

升级依赖项和使用它们的代码 设置pod的具体版本 删除派生数据[关于]文件夹