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

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


当前回答

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

其他回答

这也发生在苹果M1芯片上。

这是我的解决方案,使用罗塞塔检查打开 步骤:

转到应用程序>右击xcode >获取信息>检查使用Rosetta打开 重新启动系统。

我也在Xcode 7.2上看到过这个错误,当派生数据被损坏时(在我的情况下,我中断了一个构建,怀疑这是根本原因)。

因此,如果其他解决方案(特别是克里斯的和BraveS的,我怀疑更有可能)不适合你的问题,尝试删除派生数据(选择:窗口/项目/派生数据->删除)并重新构建。

(补充供他人参考-我知道原来的问题已经正确回答)。

也可以是您试图编译的.c文件中的#include <windows.h>。

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

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

在我的情况下,我必须加上

    target 'SomeTargetTests' do
        inherit! :search_paths
    end
to my podfile and then delete the /Pods directory and run `pod install`

(Xcode 10.1)