xcode 链接器错误:未定义符号,未找到符号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10357311/
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-15 00:07:21  来源:igfitidea点击:

Linker error: undefined symbols, symbols not found

iosxcodelinker

提问by chrisjr

I'm getting these Apple Mach-O Linker errors and I don't know how to read these things. I got these error after importing "CLCredentialHeader.h" and "CLCredentialHeader.m" in my project.

我收到这些 Apple Mach-O Linker 错误,但我不知道如何阅读这些内容。在我的项目中导入“CLCredentialHeader.h”和“CLCredentialHeader.m”后出现这些错误。

Undefined symbols for architecture armv7:
  "_OBJC_CLASS_$_SFHFKeychainUtils", referenced from:
      objc-class-ref in CLCredentialHandler.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

回答by warrenm

Make sure that SFHFKeychainUtils.mappears in the "Compile Sources" Build Phase for your build target. Sometimes, adding files to a project in Xcode doesn't add all implementation files to the appropriate targets.

确保SFHFKeychainUtils.m出现在您的构建目标的“编译源”构建阶段。有时,在 Xcode 中向项目添加文件不会将所有实现文件添加到适当的目标。

回答by hol

I get this sometimes when I drag and drop a class from another project and forget to mark "add to targets" in the window that pops up. I think this is a very legitimate question. The error messages are also not very intuitive. The solution is easy in XCode clicking on the project, and click on "Build Phases" and open the "Compile Source" then say "+". Here some pictures that say more then all the words.

有时当我从另一个项目中拖放一个类并忘记在弹出的窗口中标记“添加到目标”时,我会得到这个。我认为这是一个非常合理的问题。错误消息也不是很直观。解决方案很容易在 XCode 中单击项目,然后单击“构建阶段”并打开“编译源”,然后说“+”。这里有一些图片说的更多,然后是所有的话。

So if the error looks like this, it tells me DataAccess class is undefined.

所以如果错误看起来像这样,它告诉我 DataAccess 类是未定义的。

enter image description here

在此处输入图片说明

I recognize this as a class I just dragged and dropped into the project. I add DataAccess.m to my project

我认为这是我刚刚拖放到项目中的一个类。我将 DataAccess.m 添加到我的项目中

enter image description here

在此处输入图片说明

Originally I could have avoided it by marking "Add to targets"

最初我可以通过标记“添加到目标”来避免它

enter image description here

在此处输入图片说明

回答by Mann

If above answers does not work for you then check you have added Security framework. If not then add it in Build Phase section of Targets. Should be fine then :)

如果以上答案对您不起作用,请检查您是否添加了安全框架。如果没有,则将其添加到目标的构建阶段部分。那么应该没问题:)