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

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


当前回答

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

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

(Xcode 10.1)

其他回答

当你在你当前的项目中使用arm6、arm7架构时,任何你试图在你的项目中使用的第三方框架都是基于x86_64构建的。

例如,如果你在你的项目中使用Cocoa Pods,那么你需要添加以下脚本,以确保所有第三方框架都能确保arm6, arm7。即

示例podfile与脚本添加在结束

target 'XYZ_ProjectTarget' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!
  
  # Pods for XYZ_ProjectTarget
  pod 'pod_name'
  
  target 'XYZ_TargetTests' do
    inherit! :search_paths
    # Pods for testing
  end
  
  target 'XYZ_TargetUITests' do
    # Pods for testing
  end
  
end

post_install do |installer_representation|
  installer_representation.project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ARCHS'] = 'armv7 armv7s'
    end
  end
end

对我来说,这是在合并冲突之后开始发生的。

我试图清理和删除构建文件夹,但没有帮助。不管怎样,这个问题一直在发生。然后,我通过删除有问题的组来重新链接引用,并重新添加到项目中,它起作用了。

这个问题我已经遇到过很多次了。这通常发生在您删除构建文件夹时。

简单的解决方案是解集成并重新安装pod文件。

pod deintegrate
pod install

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

通过设置选项来修复它:

Project -> Architecture -> Build Active Architecture Only

为Yes

正确地编译和构建项目

我也遇到过同样的问题,以上的方法都行不通。我不小心删除了下面目录下的文件。

Or

~ /图书馆/开发/ Xcode / DerivedData /