Xcode 构建失败“架构 x86_64 的未定义符号" [英] Xcode build failure "Undefined symbols for architecture x86_64"

查看:33
本文介绍了Xcode 构建失败“架构 x86_64 的未定义符号"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Xcode 初学者的问题:

这是我第一次使用 Xcode 4.6.3.

我正在尝试编写一个非常简单的控制台程序,用于搜索配对的 BT 设备并将它们打印到 NSLog.

它构建时出现以下错误:

体系结构 x86_64 的未定义符号:_OBJC_CLASS_$_IOBluetoothDevice",引用自:main.o 中的 objc-class-refld:找不到架构 x86_64 的符号clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)

我疯狂地搜索.常见的问题应该是对文件的引用,其中只导入了头文件,链接器没有找到实现(*.m-file).然而,IOBluetooth 库是一个标准框架,如 Foundation Framework.

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

我也尝试过为 32 位机器构建它(构建再次失败).这显然是一个链接器错误,但我不知道它与什么相关,除了在 x86 和 x64 架构上查找 IOBluetoothDevice 的实现时存在问题,而头文件来自标准包含的框架,称为IO蓝牙?

供您参考,我的主要代码main.m"是:

#import #import //注意蓝牙的导入#import //注意蓝牙的导入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 ]);}}返回0;}

感谢您提供正确方向的任何帮助或指示.

解决方案

您的项目中似乎缺少 IOBluetooth.framework.您可以通过以下方式添加:

  • 点击左窗格左上角的项目(蓝色图标).

  • 在中间窗格中,单击构建阶段"选项卡.

  • 在Link Binary With Libraries"下,点击加号按钮.

  • 从列表中找到 IOBluetooth.framework 并点击添加.

这将确保链接器找到 IOBluetooth.framework 定义.您可以通过单击左窗格中的框架并在右窗格中查看框架的目标成员身份来看到该框架是目标的成员(请注意,出于组织目的,我已将该框架移至 Frameworks 组下):

An Xcode beginner's question:

It is my first experience with Xcode 4.6.3.

I am trying to write a very simple console program, that searches for paired BT devices and prints them to an NSLog.

It builds with the following error:

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)

I searched like crazy. The common problem should be a reference to a file, of which only the header files are imported and no implementation (*.m-file) is found by the linker. The IOBluetooth library is however, a standard Framework like the Foundation Framework.

What am I missing in my above statement?

I also have tried building it for a 32-bit machine (build fails again). It is clearly a linker error, however I have no idea, to what it relates, except that there is an issue with finding the implementation for IOBluetoothDevice, on both x86 and x64 architecture, while the header files are from a standard included Framework, called IOBluetooth?

For your information my main code "main.m" being:

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

Thanks for any help or pointers to the right direction.

解决方案

It looks like you are missing including the IOBluetooth.framework in your project. You can add it by:

  • Clicking on your project in the upper left of the left pane (the blue icon).

  • In the middle pane, click on the Build Phases tab.

  • Under "Link Binary With Libraries", click on the plus button.

  • Find the IOBluetooth.framework from the list and hit Add.

This will make sure that the IOBluetooth.framework definitions are found by the linker. You can see that the framework is a member of your target by clicking on the framework in the left pane and seeing the framework's target membership in the right pane (note I've moved the framework under the Frameworks group for organization purposes):

这篇关于Xcode 构建失败“架构 x86_64 的未定义符号"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆