objective-c Xcode 构建失败“架构 x86_64 的未定义符号”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18408531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 20:55:55  来源:igfitidea点击:

Xcode build failure "Undefined symbols for architecture x86_64"

objective-cxcodemacoscocoaiobluetooth

提问by RisingSun

An Xcode beginner's question:

Xcode 初学者的问题:

It is my first experience with Xcode 4.6.3.

这是我第一次使用 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.

我正在尝试编写一个非常简单的控制台程序,它搜索配对的 BT 设备并将它们打印到 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.

我疯狂地寻找。常见的问题应该是对文件的引用,其中只导入了头文件,链接器没有找到实现(*.m-file)。然而,IOBluetooth 库是一个标准框架,如 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?

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

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

供您参考,我的主要代码“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;
}

Thanks for any help or pointers to the right direction.

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

采纳答案by Chris Livdahl

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

看起来您的项目中缺少 IOBluetooth.framework 。您可以通过以下方式添加它:

-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.

- 在中间窗格中,单击 Build Phases 选项卡。

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

- 在“Link Binary With Libraries”下,点击加号按钮。

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

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

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

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):

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

enter image description here

在此处输入图片说明

回答by Aleksey Potapov

UPD

UPD

Apple requiresto use arm64architecture. Do not use x32 libraries in your project

Apple要求使用arm64架构。不要在您的项目中使用 x32 库

So the answer below is not correct anymore!

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



Old answer

旧答案

The new Xcode 5.1 sets the architecture armv7,armv7s,and arm64as default.

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

And sometimes the error "build failure “Undefined symbols for architecture x86_64”"may be caused by this. Because, some libs (not Apple's) were compiled for x32 originally and doesn't support x64.

有时错误“构建失败“架构x86_64的未定义符号””可能是由此引起的。因为,一些库(不是 Apple 的)最初是为 x32 编译的,不支持 x64。

So what you need, is to change the "Architectures" for your project target like this

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

NB.If you're using Cocoapods - you should do the same for "Pods" target.

注意。如果您正在使用 Cocoapods - 您应该对“Pods”目标执行相同的操作。

enter image description here

在此处输入图片说明

回答by Confused

Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_xxx", referenced from: objc-class-ref in yyy.o

架构 x86_64 的未定义符号:“_OBJC_CLASS_$_xxx”,引用自:yyy.o 中的 objc-class-ref

This generally means, you are calling "xxx" (it may be a framework or class) from the class "yyy". The compiler can not locate the "xxx" so this error occurs.

这通常意味着,您正在从“yyy”类中调用“xxx”(它可能是一个框架或类)。编译器无法定位“xxx”,因此发生此错误。

You need to add the missing files(in this case "xxx") by right click on your project folder in navigator window and tap on "Add files to "YourProjectName"" option.

您需要通过右键点击导航窗口,然后点击你的项目文件夹“添加缺少的文件(在这种情况下,“XXX”)的文件添加到”为yourprojectname”选项。

A popup window will open your project files in Finder. There, you can see the missing files and just add them to your project. Don't forget to check the "Copy items if needed" box. Good luck!!

一个弹出窗口将在 Finder 中打开您的项目文件。在那里,您可以看到丢失的文件并将它们添加到您的项目中。不要忘记选中“如果需要,请复制项目”框。祝你好运!!

回答by Ali Beadle

I have also seen this error on Xcode 7.2 when the derived data becomes corrupted (in my case I interrupted a build and suspect that was the root cause).

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

So if the other solutions (notably Chris's and BraveS's which I suspect are more likely) do not fit your problem try deleting derived data (Select: Window / Projects / Derived Data -> Delete) and re-building.

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

(Added for reference by others - I know the original question has been answered correctly).

(添加供其他人参考 - 我知道原始问题已得到正确回答)。

回答by William Cerniuk

Under Xcode 9.0b5 you may encounter this because Xcode 9.0b5 has a bug in it where when you add source code, it does not honor the target settings. You must go in and set each file's target manually afterwords:

在 Xcode 9.0b5 下,您可能会遇到这种情况,因为 Xcode 9.0b5 中存在一个错误,即当您添加源代码时,它不支持目标设置。您必须进入并手动设置每个文件的目标:

Xcode project with manual target membership illustration

带有手动目标成员资格说明的 Xcode 项目

回答by Udaya Sri

In my Case , it was not a library, it was some classes ..

在我的案例中,它不是图书馆,而是一些类..

Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_ClassNmae", referenced from: objc-class-ref in SomeClassName" . . .

d: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

体系结构 x86_64 的未定义符号:
“_OBJC_CLASS_$_ClassNmae”,引用自:SomeClassName 中的 objc-class-ref”...

d:找不到架构 x86_64 的符号

clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)

SolutionI had several targets in Xcode with several schemas ( Production , Dev etc ) .. some of my newly added implementation ( Class.m ) were missing in

解决方案我在 Xcode 中有几个目标,有几个模式(生产、开发等)......我的一些新添加的实现(Class.m)在

Xcode->Targets->Build Phases->Compile Sources

Xcode->Targets->Build Phases->Compile Sources

So I had to add them manually.

所以我不得不手动添加它们。

then I could compile & build successfully.

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

回答by ylgwhyh

I also encountered the same problem , the above methods will not work . I accidentally deleted the files in the following directory on it . enter image description here

我也遇到了同样的问题,上面的方法都不行。我不小心删除了以下目录中的文件就可以了。 在此处输入图片说明

Or

或者

~/Library/Developer/Xcode/DerivedData/

〜/图书馆/开发人员/Xcode/DerivedData/

enter image description here

在此处输入图片说明

回答by whyoz

When updating to Xcode 7.1, you might see this type of error, and it can't be resolved by any of the above answers. One of the symptoms in my case was that the app runs on the device not in the simulator. You'll probably see a huge number of errors related to pretty much all of the frameworks you're using.

更新到 Xcode 7.1 时,您可能会看到此类错误,并且无法通过上述任何答案解决。在我的案例中的症状之一是该应用程序在设备上运行而不是在模拟器中运行。您可能会看到大量与您使用的几乎所有框架相关的错误。

The fix is actually quite simple. You just need to delete an entry from the "Framework Search Paths" setting, found in your TARGETS > Build Settings > Search Paths section (make sure the "All" tab is selected)

修复实际上非常简单。您只需要从“框架搜索路径”设置中删除一个条目,该设置位于“目标”>“构建设置”>“搜索路径”部分(确保选择了“全部”选项卡)

enter image description here

在此处输入图片说明

If you see another entry here (besides $(inherited)) for your main target(s) or your test target, just delete the faulty path from all targets and rebuild.

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

回答by Aggressor

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.

我发现如果将包含 Objective-C 文件的文件夹拖到项目中,也会发生这种情况。如果该文件夹显示为蓝色,我认为这表明它没有正确链接。您可以验证这一点(如果您使用版本控制),因为每当您添加新文件时,pbxproj 文件都应该使用指向这些新文件的链接进行更新。但是,您可能会发现在添加了 pbxproj 文件没有更改的文件夹后(因此存在链接错误)。所以你会得到自动完成工作,它会找到你导入的类,但是当它实际构建图像时,它会失败并显示此错误代码。

The solution is to not add the folder but rather add the files. Do this and you should see the pbxproj file update and it should fix this error.

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

This also assumes you've done what was suggested above and have properly linked all the right frameworks.

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

回答by lonesomewhistle

I tried just about everything here but my problem turned out to be the remnants of a previous cocoapods build. What worked for me was:

我在这里尝试了几乎所有的东西,但我的问题原来是以前的 cocoapods 构建的残余。对我有用的是:

  1. rm -Rf Pods; pod install
  2. Delete Derived Data (Window/Projects... select your target. click Delete Button)
  3. Rebuild
  1. rm -Rf Pods; pod install
  2. 删除派生数据(窗口/项目...选择您的目标。单击删除按钮)
  3. 重建