Resolving symbol(s) not found for architecture x86_64

Become a Subscriber

In my previous article I brought in an external library called Crypto. After having the headers setup I thought everything was going to work just fine when suddenly this crazy error popped up.

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_Crypto", referenced from:
      __TMaCSo6Crypto in AuthHelper.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

What the hell does that even mean!? Well if we look further into it without the scary jargon it is essentially saying inside AuthHelper there are unrecognized symbols. Now from the previous article for me that meant that the header files I was importing to give me access to Encryption functions was messing up somewhere.

I’ll be honest it took me 2 days of searching around to try and find a solution. I finally came across a wonderful Stack Overflow here that helped me solve this issue. Thanks Joe from Stack Overflow, you saved me from more embarrassment at yelling at my computer in a coffee shop, I owe you a drink dude!

For the sake of my own memory I’ll rewrite it here.

The common causes for “Undefined symbols for architecture” are:

You import a header and do not link it against the correct library. This is common, especially for headers for libraries like QuartzCore since it is not included in projects by default. To resolve:

  • Add the correct libraries in the Link Binary with Libraries section of the Build Phases.

  • If you want to add a library outside of the default search path you can include the path in the Library Search Paths value in the Build Settings and add -l{librarynamewithoutliband_suffix} (eg. for libz.a use -lz) to the other Other Linker Flags section of the Build Settings

(This is the one that helped me with my issue) You copy files into your project but forget to check the target to add the files to. To resolve:

  • Open Build Phases for the correct target, expand Compile Sources and add the missing .m files

You include a static library that is built for another architecture like i386, the simulator on your host machine. To resolve

  • If you have multiple library files from your libraries vendor to include in the project you need to include the one for the simulator (i386) and the one for the device (armv7 for example).

  • Optionally, you could create a fat static library that contains both architectures

And with that hopefully the joyous screen of Build Succeeded shows up!

Cheers!