Linker error: undefined symbols, symbols not found

2020-02-29 19:26发布

问题:

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.

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)

回答1:

Make sure that SFHFKeychainUtils.m appears 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.



回答2:

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.

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

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

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



回答3:

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



标签: ios xcode linker