320

This problem has been driving me crazy, and I can't work out how to fix it...

    Undefined symbols for architecture armv7:
  "_deflateEnd", referenced from:
      -[ASIDataCompressor closeStream] in ASIDataCompressor.o
  "_OBJC_CLASS_$_ASIDataDecompressor", referenced from:
      objc-class-ref in ASIHTTPRequest.o
  "_deflate", referenced from:
      -[ASIDataCompressor compressBytes:length:error:shouldFinish:] in ASIDataCompressor.o
  "_deflateInit2_", referenced from:
      -[ASIDataCompressor setupStream] in ASIDataCompressor.o
ld: symbol(s) not found for architecture armv7
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

I think it has to do with:

ld: symbol(s) not found for architecture armv7

But I have added: libz.1.2.3.dylib and it's not helping, anyone got any ideas?

Forge
  • 6,538
  • 6
  • 44
  • 64
Alex Trott
  • 4,576
  • 4
  • 23
  • 30
  • 1
    Another possibility not covered in any of the existing answers is that you might be using the `-ObjC` other linker flag and so Obj-C from external static libraries that you're using which shouldn't be visible (such as from Parse's), are visible. See my answer if this is the case: http://stackoverflow.com/a/26151208/901641 – ArtOfWarfare Oct 01 '14 at 21:47
  • 2
    As a rule of the thumb, somethimes XCode gives the kind of errors like Match-O and symbol not found for architecture i386 (or other) when files were not added to the project. Yo can right click on the project folder and do "Add file to ". – Rudolf Real Apr 07 '15 at 14:17
  • 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 You can inspect the C++ symbols demangled with this: nm -gC file.o – James Alvarez Sep 08 '16 at 23:44
  • Can someone here please help me? I am getting the below error but none of the above solution works for me. I have already spent days with all possible settings. ``Undefined symbols for architecture armv7: "YGConfig::YGConfig(int (*)(YGConfig*, YGNode*, YGLogLevel, char const*, void*))", referenced from: _YGConfigNew in libyoga.a(Yoga.o) ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)`` – red-devil Jan 06 '19 at 09:13
  • I fixed similar error with this way https://stackoverflow.com/a/73011491/11079607 – Taras Jul 17 '22 at 15:47

40 Answers40

512

Common Causes

The common causes for "Undefined symbols for architecture armv7" are:

  1. You import a header and do not link 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{library_name_without_lib_and_suffix} (eg. for libz.a use -lz) to the Other Linker Flags section of Build Settings.

  2. You copy files into your project but forgot to check the target to add the files to. To resolve:

    • Open the Build Phases for the correct target, expand Compile Sources and add the missing .m files. If this is your issue please upvote Cortex's answer below as well.

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



Original Answer:

You have not linked against the correct libz file. If you right click the file and reveal in finder its path should be somewhere in an iOS sdk folder. Here is mine for example

/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib

I recommend removing the reference and then re-adding it back in the Link Binary With Libraries section Build Phases of your target.

Community
  • 1
  • 1
Joe
  • 56,979
  • 9
  • 128
  • 135
  • 4
    It may also be because you need to add the word "-licucore" in project settings / Other Linker Flags. It was added automatically for my debug build but not the release one so wouldn't compile. – JulianB Nov 02 '11 at 23:25
  • 4
    I had the same issue. Didn't really read the install notes properly so hadn't noticed that the new version of bugsense needs libz binary added in the build phases. – Max MacLeod Nov 08 '12 at 09:33
  • 2
    Are you sure that you've included an @implementation section in your respective .m file for all classes you've declared in your header file? – slcott Jun 13 '13 at 02:27
  • 7
    I just want to add I think it was really respectful of you to reference another answer to this question and tell us to up vote it if that helped. – Andrew Sep 16 '13 at 00:03
  • Thanks for help! :) For me helped typing explicitly in Other Linker Flags section: `-framework `. I had problem with XCTest, so I had to add `-framework XCTest`. Thanks! :) – piotr_ch Oct 23 '14 at 14:18
  • I had this happen due to #1 where I had the same library name twice in the library search path and it was picking up the wrong one, even when I changed the order of directories in Xcode's project settings. Once I removed the incorrect library .a file it fixed it. – Liron Yahdav Aug 05 '17 at 05:36
  • Can someone here please help me? I am getting the below error but none of the above solution works for me. I have already spent days with all possible settings. ``Undefined symbols for architecture armv7: "YGConfig::YGConfig(int (*)(YGConfig*, YGNode*, YGLogLevel, char const*, void*))", referenced from: _YGConfigNew in libyoga.a(Yoga.o) ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)`` – red-devil Jan 06 '19 at 09:13
197

I had a similar issue last night and the problem, was related to the fact that I had dragged a class from the Finder to my project in Xcode.

The solution was to go the the Build Phases tab and then the Compile Sources and make sure you drag the class to the list.

tvkanters
  • 3,519
  • 4
  • 29
  • 45
Cortex
  • 2,300
  • 2
  • 15
  • 14
  • 6
    I wish I had realized this was the answer I was looking for earlier- Alternatively you can make sure to check 'Add to targets' when copying classes. – T. Markle Aug 22 '12 at 04:33
  • 1
    Whoa...so glad the fix was this easy! To be clear, if you add a class by dragging from the finder into your project, XCode doesn't always add them to your build phases list apparently. I just hit the "+" button in "Compile Sources" under build phases, added all the offending files, and it compiled straight away. – Amos Sep 04 '12 at 15:16
  • 2
    Wow. Apple *really* needs to reconsider their error messages. – devios1 Mar 15 '13 at 01:02
  • 2
    Another way to fix this is select file that is said to be missing. and open the "Utilities" slide out bar. (Thats the far right one) And choose the "File Inspector". Then make sure there is a check in the project under "Target Membership". I'm using Xcode 4.6.2 – zingle-dingle May 07 '13 at 16:57
  • 1
    I didn't know which file was missing, so I showed the Build Phases in the assistant editor (the second editing view). I opened the offending file in the left editing view and checked that each of the imported files existed in Build Phases. I added the one that didn't and it was resolved. – Dan Sandland Aug 13 '13 at 01:14
  • 1
    Have to agree with Reuben. After working with Visual Studio and Netbeans, Xcode is a real disappointment (so ridiculously complicated). – Gerry Oct 22 '14 at 18:12
  • Can someone here please help me? I am getting the below error but none of the above solution works for me. I have already spent days with all possible settings. ``Undefined symbols for architecture armv7: "YGConfig::YGConfig(int (*)(YGConfig*, YGNode*, YGLogLevel, char const*, void*))", referenced from: _YGConfigNew in libyoga.a(Yoga.o) ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)`` – red-devil Jan 06 '19 at 09:14
38

I had a similar issue and I had to check "Build Active Architecture Only" on each of the Project configurations (Debug, Release and Deployment) and in the Build Settings of the Target.

Alex Zavatone
  • 4,106
  • 36
  • 54
  • 3
    Also did the trick for me. Was just needed in the main project though. – Alexis C. Oct 10 '12 at 10:20
  • 5
    I encounter the same issues. The `Build Active Architecture Only` settings are different between `Pods` and my project. At the link stage, it failed. – AechoLiu Jan 27 '16 at 07:12
21

Another possible cause of "undefined symbol" linker errors is attempting to call a C function from a .mm file. In this case you'll need to use extern "C" {...} when you import the header files.

Linker error calling C-Function from Objective-C++

Community
  • 1
  • 1
user2166865
  • 311
  • 2
  • 3
14

I had a similar issue with that. The class name after _OBJC_CLASS_$_ was actually my class. The reason was I didn't tick "Add to Target" when I drag the source code files into navigation list.

My solution was:

  1. delete the class from the navigation list and choose "remove reference only"

  2. drag the source code files again and make sure the tick box for "add to Target" is ticked. The tick box is just under "Copy if needed" and "Create group".

syoleen
  • 281
  • 2
  • 10
  • Just to add: although this is NOT THE MOST COMMON CAUSE of the error, I just your answer (didn't tick the box) happen to me now. – Adam Jun 28 '12 at 12:06
8

There is usually a alias without the version identifier that is linked to the current version, in this case libz.dylib is linked to libz.1.2.5.dylib. Use the base alias instead of the versioned one.

zaph
  • 111,848
  • 21
  • 189
  • 228
7

I had the same problem when I use admob library, I fixed it changing "Architectures" to "Standard architectures armv7, armv7s" without including 64-bit. Build Settings

pabloverd
  • 614
  • 8
  • 8
5

Under Target -> Build Settings -> Apple LLVM compiler language: setting 'C++ Language Dialect' and 'C++ Standard Library' to Compiler default helped solve it.

user1368045
  • 107
  • 1
  • 7
5

I only added the libz.1.2.5.dylib to my project and it worked like a charm.

Steps -

  1. Go to Build Phases.
  2. Link Binary With library - use the '+' button to choose frameworks and libraries to add.
  3. Select libz.1.2.5.dylib from the list.
  4. Build and run.
girish_vr
  • 3,041
  • 1
  • 24
  • 27
5

I had a similar issue and saw errors related to "std::"

I changed Build Settings -> Apple LVM 5.0 - Language C++ -> C++ Standard Library

from libc++ (LLVM C++ Standard Library with C++11 support) to libstdc++ (GNU C++ Standard Library)

Andrew Soltan
  • 609
  • 6
  • 5
5

If you have the flag -ObjC under your Target > Build Settings > Other Linker Flags and you're getting this issue, consider removing it. If you intentionally added it because you need to load some Obj-C code from a static library that wouldn't normally be loaded otherwise, IE, an Obj-C category, then you should use -force_load <path> instead of -ObjC.

<path> should be relative to your Xcode project directory. IE, if your directory structure looks like this:

iOSProject
  + iOSAPI.framework
      + iOSAPI
  + iOSAPI.xcodeproj

Then you should have this flag set for Other Linker Flags:

-force_load iOSAPI.framework/iOSAPI

If you want to include multiple libraries like that, then you should include a separate -force_load line for each of them.

-force_load iOSAPI.framework/iOSAPI
-force_load another.framework/another
ArtOfWarfare
  • 20,617
  • 19
  • 137
  • 193
4

Here's how I got this problem:

I added a .h, .m and NIB from another project by dragging them onto my project navigator. Xcode didn't add them to the Build Phases properly.

Check my answer because I had a similar problem that I was able to solve by doing some steps.

Community
  • 1
  • 1
Himanshu Agnihotri
  • 2,360
  • 4
  • 23
  • 30
4

Probably some classes are missing from your target. This usually happens when you rename/remove/add new classes files to your project. To fix add the newly added classes to some targets.

Select the class in the Project Navigator (right sidebar) , open the Utilities sidebar (right sidebar), from the Utilities select the File Inspector (file like icon), under the Target Membership tab tick your targets. This is all to avoid the "Remove reference" and add again with ticking "Add to targets" trick.

So: Select Class -> Utilities (File Inspector) -> Target Membership -> Tick the targets you want.

andrei
  • 1,009
  • 11
  • 16
4

I have have multiple @interfaces in the .h file and hadn't yet included the all of the corresponding @implementation directives. Make sure that they are all balanced out.

James
  • 323
  • 3
  • 8
3

Go to your project, click on Build phases, Compile sources, Add GameCenterManager.m to the list.

3

This fixed my problem: The dependency I am using is not supporting armv7. So I had no other option than to remove it. Armv7 is used for only very old iphones anyway (like iphone 4).

  • Go 'Build Settings / All'
  • Set 'Valid Architectures' to 'arm64 arm64e'
chickens
  • 19,976
  • 6
  • 58
  • 55
3

if you're dealing with the iOS5 upgrade, I found that for compiling a project written to target 4.3, I could just rename libz.1.2.3.dynlib in the Project Navigator to libz.1.2.5.dynlib and it compiled.

My iPhoneOS50SDK/usr/lib folder has no libz.1.2.3.dynlib--don't know whether it's a beta thing or just natural upgrade.

Stan
  • 434
  • 1
  • 4
  • 14
2

I didn't find this suggestion here so here it goes: if your project has more than one target (ie one for OSX and one for iOS) then you must link the relevant libraries for each target.. so for example in my case I needed AudioToolbox.. I had to add it once for OSX and once for iOS (under the frameworks folder, you must have a duplicate of each library for each target.. if you see only one.. then that's a red flag)

abbood
  • 23,101
  • 16
  • 132
  • 246
  • This answer helped me. However, my situation was even more straight forward... I simply forgot to add a framework that my codebase referenced. In my case I failed to load AVFoundation.framework. – John Erck Dec 27 '12 at 21:42
  • Yep, I simply forgot to add a framework under the "Link Binary with Libraries" phase. – Max Jan 10 '19 at 22:14
2

I was facing an issue with PJSIP libraries,

Tried the following in other linker flags in project and able to resolve the error: -framework Foundation -framework UIKit

Above linker flags are used in Siphone Project over github. These settings will help you resolve problems related to linking of C++ libraries.

Mohsin Khubaib Ahmed
  • 1,008
  • 16
  • 32
Adeesh Jain
  • 645
  • 10
  • 22
  • I am having the same problem with PJSIP librabries, Can you explain the solution in detail – Rajat Jain Mar 13 '18 at 12:31
  • Set the following values in other linker flags of project build setting: -framework Foundation -framework UIKit – Adeesh Jain Mar 14 '18 at 05:45
  • Error Message: ignoring file /Users/user/Downloads/pjproject-2.7.2/pjsip-apps/src/pjsua/ios/libyuv.a, file was built for archive which is not the architecture being linked (i386): /Users/user/Downloads/pjproject-2.7.2/pjsip-apps/src/pjsua/ios/libyuv.a Undefined symbols for architecture i386: "_pjsip_register_method", referenced from: – Rajat Jain Mar 14 '18 at 05:58
  • It seems like you are trying to run app on simulator and libyuv.a is not built for simulator architecture i386. try running app on device directly – Adeesh Jain Mar 14 '18 at 21:36
  • I want to integrate Pjsip in Swift. I tried creating bridging headers but it did not worked. Can you give me some idea? – Rajat Jain Mar 20 '18 at 17:36
1

Finally i've figured it out, I solved this issue by adding absent framework to target->Build Phases->Link Binary With Libraries

lomec
  • 1,356
  • 1
  • 11
  • 10
1

I once had this problem. I realized that while moving a class, I had overwritten the .mm file with .h file on the destination folder.

Fixing that issue fixed the error.

Wouter J
  • 41,455
  • 15
  • 107
  • 112
1

I received the 'Undefined symbols for architecture armv7:' error when trying to compile a project that had the target build setting for 'C++ Standard Library' set to 'libc++' (necessary as the project was using some features from C++ 11), and the project included a sub-project that had the same setting set to 'libstdc++' (or compiler default as it is currently).

Changing the sub-project's 'C++ Standard Library' setting to libc++ fixed it, but only after first setting the deployment target for the sub-project to 5.0 or above (5.0 is necessary for libc++).

Si.
  • 379
  • 2
  • 7
1

I give you more suggestions that you can check when other common suggestions are not help.

If you link with other project(libxxx.a) you might sometimes meet strange problem which you can find the symbol with tools like nm but they just can not find the symbols in ld. Then you should check if the two projects are built in the same flags, some of them may affect the binary format.

  1. check c++ compiler.
  2. check c++ dialect setting.
  3. check c++ runtime type support. (-frtti/-fnortti)
  4. check if there is .a with the same name appears elsewhere, could be beyond the wanted file in the link path list. remove them.
fluke
  • 660
  • 8
  • 16
1

I got this problem when I run app on iphone5s, it was solved by add arm64 to Architectures.

alexqinbj
  • 1,091
  • 3
  • 13
  • 27
1

I had the same problem. I tried every thing from the huge list of answer but in the end my problem was: I'm working with openCV so I need to combine C++ code in my code. To do this you should change the files which use objective-c and C++ to .mm I didn't changed one file and this file has no connection to the C++ code but I had to change it.

user2743760
  • 201
  • 2
  • 9
1

I had this issue, when installing shareKit. It worked in the simulator, but not on the device. I removed -all_load from the Other Linker Flag and everything works fine in both simulator and iphone device.

Jordan
  • 21,746
  • 10
  • 51
  • 63
1

In my case, I'd added a framework that must be using Objective C++. I found this post:

XCode .m vs. .mm

that explained how the main.m needed to be renamed to main.mm so that the Objective-C++ classes could be compiled, too.

That fixed it for me.

Community
  • 1
  • 1
Vito Andolini
  • 425
  • 1
  • 5
  • 14
1

I use to face that issue when the module (file .m) is not in the target that I am working with.

1

For me the problem was that i forget to set value for my constants in the .m (implementation)

file const kFooKey = @"Foo";
Jakub Truhlář
  • 20,070
  • 9
  • 74
  • 84
1

I also added files through Dragging and Dropping. What I did, I removed references of all the files (Excluding frameworks) then added them again properly via Add Files To Project option, problem gone.

Vaibhav Saran
  • 12,848
  • 3
  • 65
  • 75
1

If you're building from Unity3D 5 and also using a Prime31 plugin and you're getting this error it's probably due to a duplicate .dll. If you look through your warnings in Unity's editor one of them will tell you this and warn that it could cause build errors. To see if this is the case, type P31 in your project search field and it should pop right up, maybe even more than one. The duplicate's will have a ' 1' at the end of the file name. This is probably caused from updating the plugin in editor via the store or the Prime31 menu tab.

Dela Torre
  • 51
  • 8
1

For what it is worth, mine was fixed after I went to target->Build Phases->Link Binary With Libraries, deleted the libstdc++.tbd reference, then added a reference to libstdc++.6.0.9.tbd.

n8n8baby
  • 493
  • 5
  • 16
0

I was facing the same problem when I included one third party framework.

The issue got resolved when I removed armv7s from the Valid Architectures entry in Build Settings of the target, it starts working.

Easwaramoorthy Kanagaraj
  • 3,925
  • 8
  • 36
  • 62
0

rename your m file (which includes methods funcs) to mm or vice versa will fix your problem. mine solved renaming mm to m or m to mm.

Zen Of Kursat
  • 2,672
  • 1
  • 31
  • 47
0

Try to implement at least one non-inline function of your derived class. If you don't do this, the linker might avoid creating type info for that class.

Michael Litvin
  • 3,976
  • 1
  • 34
  • 40
0

In Xcode Version 6.3.2 , I solved the exactly same problem by adding Library libxml2.dylib and libz.dylib In Link Binary With Libraries !

Stephen Chen
  • 3,027
  • 2
  • 27
  • 39
0

In my case, I had a similar problem when I created a new branch under source control.

I was able to resolve this problem by simply going Product>Clean

Anthony Dito
  • 3,610
  • 3
  • 29
  • 56
0

I had this warning, when wrote two classes in .h file of another class, but FORGOT to write the implementation for this classes in .m file.

Nike Kov
  • 12,630
  • 8
  • 75
  • 122
0

Go TARGETS -> General -> Deployment Info -> set Target 8.1 or 10.0

Framework or Library have no ARMV7 Architecture.

0

If you faced this issue with your Flutter project while building in Release mode - that's what helped me:

  1. Set your build system to New Build System in File > Project Settings…
  2. delete folders ios and build_ios from your project folder.
  3. create ios module by executing flutter create . from your project folder.
  4. open Xcode and:

    • set the IOS Deployment Target to at least 9.0 in PROJECT > Runner
    • check your Signing & Capabilities
    • make sure your Build Configuration is set to Release in Edit Scheme... and build for Generic iOS Device
  5. execute pod install from your project folder

  6. execute flutter pub get from your project folder

now open your Xcode and build or archive it: Product > Build (or Archive)

Kirill Karmazin
  • 6,256
  • 2
  • 54
  • 42