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

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


看起来您在项目中缺少包含ioblutooth .framework。您可以通过以下方式添加:

单击左窗格左上方的项目(蓝色图标)。 在中间窗格中,单击Build Phases选项卡。 在“Link Binary With Libraries”下,点击加号按钮。 从列表中找到ioblutooth .framework,然后点击Add。

这将确保ioblutooth .framework定义被链接器找到。您可以通过单击左侧窗格中的框架,并在右侧窗格中看到该框架的目标成员,从而看到该框架是目标成员(注意,出于组织目的,我已经将该框架移动到Frameworks组下):


UPD

苹果要求使用arm64架构。在项目中不使用x32库

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


旧的答案

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

有时错误“build failure”“Undefined symbols for architecture x86_64”可能是由此引起的。因为,一些库(不是苹果的)最初是为x32编译的,不支持x64。

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

NB。如果你正在使用Cocoapods -你应该为“Pods”目标做同样的事情。


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

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

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


架构x86_64的未定义符号:"_OBJC_CLASS_$_xxx", 引用: yyy.o中的Objc-class-ref

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

你需要添加丢失的文件(在本例中是“xxx”),右键单击导航窗口中的项目文件夹,点击“将文件添加到“YourProjectName”选项。

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


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

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

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


我也犯了同样的错误,因为我没有删除文件,而是删除了对该文件的引用。在Finder中定位文件并删除它会有所帮助。


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

Or

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


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

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


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

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

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

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

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

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


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

rm -Rf Pods;圆荚体安装 删除派生数据(窗口/项目…选择你的目标。点击删除按钮) 重建


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

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

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


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


在Xcode 9.0b5中,你可能会遇到这种情况,因为Xcode 9.0b5有一个bug,当你添加源代码时,它不遵守目标设置。你必须在后面手动设置每个文件的目标:


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


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

通过设置选项来修复它:

Project -> Architecture -> Build Active Architecture Only

为Yes

正确地编译和构建项目


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)


这可能会帮助到某些人。我花了好几天才想明白。我在OBJ-C工作,我去了:

编译源代码并添加新的VC。m文件。

我正在使用遗留代码,我通常是一个敏捷的新手,所以我甚至没有想过将我的.m文件导入到源代码库中。

编辑:

第二次遇到这个问题,结果就不一样了。这个答案在5个小时的调试之后拯救了我。尝试了这个线程上的所有选项。https://stackoverflow.com/a/13625967/7842175如果这对你有帮助,请给他信用,但基本上你可能需要在文件检查器中将你的文件设置为目标。

总而言之,这是一个非常模糊的错误代码,可能是由很多原因引起的,所以继续尝试不同的选项。


有时,我忘记从Release-universal复制库,并错误地从Release-iphoneos复制。通常Release-iphoneos包含。a文件,该文件已为X86裁剪。所以它给出了误差。


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

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

pod deintegrate
pod install

我通过在构建设置中的其他链接器标志中添加“-lc++”来解决这个问题。


在我的情况下,删除选择的目标成员,然后再次选择修复问题。

查看William Cerniuk的答案和附件照片。


在我的案例中,问题是编译框架架构。 我运行Xcode 11和使用Swift 5.1

我有三个目标,比如: MyApp MyAppTests MyAppFrameWork

我试图运行测试,但MyAppFrameWork产品是为通用iOS设备编译的,测试目标需要一个arm x86-64,所以我重新构建了iOS模拟器和测试用例成功开始运行的框架。


帮助我的是在抛出错误的项目中向我的/podspec添加s.static_framework = true。


在我的情况下,我得到这个错误:架构x86_64未定义的符号:“_OBJC_CLASS _ $ _ RCTImageLoader”

我能够通过在Podfile文件中添加以下一行来修复它:

pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'

参考


架构x86_64的未定义符号

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

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


当你在你当前的项目中使用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

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

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

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