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

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


当前回答

架构x86_64的未定义符号

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

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

其他回答

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

Or

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

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

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

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

对我来说,不是图书馆,而是一些课程。

架构x86_64的未定义符号: "_OBJC_CLASS_$_ClassNmae",引用自:objc-class-ref in SomeClassName”… D:没有找到架构x86_64的符号 Clang: error: linker命令失败,退出码为1(使用-v查看 调用)

解决方案 我在Xcode中有几个目标和几个模式(生产,开发等)。我的一些新添加的实现(类。M)在

Xcode->目标->构建阶段->编译源代码

所以我必须手动添加它们。

然后我就可以成功编译和构建了。

If you're getting this error when trying to link to a C file, first double check the function names for typos. Next double check that you are not trying to call a C function from a C++ / Objective-C++ environment without using the extern C {} construct. I was tearing my hair out because I had a class that was in a .mm file which was trying to call C functions. It doesn't work because in C++, the symbols are mangled. You can actually see the concrete symbols generated using the nm tool. Terminal to the path of the .o files, and run nm -g on the file that is calling the symbol and the one that should have the symbol, and you should see if they match up or not, which can provide clues for the error.

nm -g file.o

你可以这样检查c++符号:

nm -gC file.o

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文件更新,它应该会修复这个错误。

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