272

I am getting a Apple Mach-O Linker Error everytime I import a file from CocoaPods.

Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_FBSession", referenced from: someFile
ld: symbol(s) not found for architecture arm64

I get about 12 of these, for the various Pods I use.

I am trying to build for the iPhone 5S using XCode 5.

I've been trying various solutions here on SO, but haven't got any of them to work yet.

How do I fix this Apple Mach-O Linker Error?


Just found another warning that might be interesting, I hope this leads me to the solution:

Ignoring file ~/Library/Developer/Xcode/DerivedData/SomeApp/Build/Products/Debug-iphoneos/libPods.a, 

file was built for archive which is not the architecture being linked (arm64):~/Library/Developer/Xcode/DerivedData/someApp/Build/Products/Debug-iphoneos/libPods.a

madhead
  • 31,729
  • 16
  • 153
  • 201
GangstaGraham
  • 8,865
  • 12
  • 42
  • 60
  • Simple Solution Go to Target ->Linking -> other linker Flag and add $(inherited) in other linker flag in both Debug and Release. – Mihir Oza Feb 03 '16 at 11:10
  • In my case the issue was with a Swift package I had added as a remote dependency to an Xcode project. The Swift package compiled successfully on its own despite missing a dependency in Package.swift. This is because one of the _included_ dependencies had the same exact dependency, so the project compiled successfully using the indirect dependency; but when imported as a dependency itself, it did not. The solution was adding the missing dependency to the library's Package.swift. – shoe May 24 '22 at 21:14
  • In my case, using flutter_unity_widget and "Export IOS (Debug)" from Unity, I got this as a build error on the Flutter app, where all the undefined symbols were related to `il2cpp::utils::Debugger::`. I was able to get around this problem by just always doing "Export IOS (Release)" from Unity instead. I'm still able to build the Flutter app for debugging on an iPhone, even though the Unity library is built for release. – Tommy Elliott Nov 30 '22 at 16:02

45 Answers45

273

If your Architectures and Valid Architectures are all right, you may check whether you have added $(inherited) , which will add linker flags generated in pods, to Other Linker Flags as below: enter image description here

chancyWu
  • 14,073
  • 11
  • 62
  • 81
  • 8
    @chancyWu Could you explain? – Paweł Brewczynski May 16 '15 at 06:25
  • 5
    also if this still doesn't work, add @(inherited) to Library Search Paths too. – Enrico Susatyo Jun 10 '15 at 04:52
  • 1
    Lol , ignored `Use the $(inherited) flag` terminal warning. And error brought me here. saved my day. – Sushil Sharma Jul 30 '15 at 09:13
  • 3
    I'm working with Xcode 7.2 and in Other Linker Flags -> Debug I see: -weak_framework CoreFoundation -weak_framework UIKit -weak_framework AVFoundation -weak_framework CoreMedia -weak-lSystem -ObjC ... here I added $(inherited) but it doesn't work – Alessandra Feb 25 '16 at 13:37
  • what is the purpose of $(inherited) if the extension which uses the library from the target in which it is already embeded. Why cant it pick it automatically. – nr5 Feb 28 '17 at 10:49
  • @chancyWu maybe you can help with my [issue](https://stackoverflow.com/questions/52579486/xcode-build-error-after-updating-to-swift-4-2-undefined-symbols-for-architectu) – user287474 Sep 30 '18 at 17:42
  • I kept only `$(inherited)` in `Other Linker Flags` & it worked. – Udaya Sri Sep 15 '20 at 08:20
125

The issue is that the cocoapods have not been built for arm64 architecture yet thus they cannot be linked when you build them. Likely you cannot use those packages until they are updated and use that architecture. You can fix the linker error by going to project -> target (your project name) -> build settings and change architectures to standard architectures (armv7, armv7s), and valid architectures to armv7, armv7s.

Note though, this means you won't get the full power of the 64 bit processor. You said you are building for the 5s, so there may be some reason you need this. If you for some reason absolutely need that power (perhaps you are building a game), and desperately need those files, you could submit a pull request and then recompile the project to arm64 by setting those same fields to arm64 in the files you pulled from the open source projects. But, unless you really need these files to be 64 bit compatible, that seems like a bit of overkill for now.

EDIT: Some people also reported that setting Build For Active Architectures to YES was also necessary to solve this problem.

As of 2014-04-28 the setting should look something like this:

enter image description here

Kit Sunde
  • 35,972
  • 25
  • 125
  • 179
AdamG
  • 3,718
  • 2
  • 18
  • 28
  • 4
    This solved the error, for running on the simulator, however, it did not solve the error for running on the device. Pods was rejected for libPods.a because its architectures '' (for some reason, it isn't detecting it - although I can see it in Xcode) didn't contain all required architectures 'armv7 armv7s' – GangstaGraham Oct 06 '13 at 21:29
  • 7
    Ok, I got this by setting Build For Active Architectures To Yes. Thank you so much! – GangstaGraham Oct 06 '13 at 21:32
  • 2
    Aside: you can use the `file` command in Terminal to tell what architectures a static library supports. – funroll Nov 20 '13 at 23:37
  • These suggestions didn't fix it for me... I still get "Pods was rejected as an implicit dependency for libPods.a because its architectures arm64 didn't contain all required architectures armv7 armv7s – shim Mar 11 '14 at 20:30
  • @shim this happened to the initial poster. It looks like the solution is to also set "Build For Active Architectures" to "yes." – AdamG Mar 13 '14 at 17:59
  • Actually the solution that worked for me was to set it to "No" but also had to do this for the "Pods" project in the workspace, since they're separate. – shim Mar 14 '14 at 06:14
  • 8
    Just came in here to add to the chorus: selecting YES for BUILD FOR ACTIVE ARCHITECTURES is the best option here. – Wells Mar 28 '14 at 20:35
  • Thanks. I was experiencing this issue when using YAJL-Objc. Seemingly working now. Thanks. – Luke Smith Jun 18 '14 at 08:19
  • 1
    You are an amazing person. Thanks – MCMatan Jul 11 '14 at 09:35
  • 61
    This is no longer a solution. Apple now demands support for 64 bit for all deployments. –  Nov 06 '14 at 15:43
  • I tried it with the method listed in the answer and it was still giving me issues (but with armv7s now). It looks like the latest version of OpenCV is the culprit. I tried it with v2.4.9.1 and the app now builds fine. This is what I have in the Podfile: `pod 'OpenCV', '~> 2.4.9.1'` – KrispyDonuts Mar 31 '15 at 05:31
  • Hey, can we submit in AppStore using that "Build Active Architecture Only" to YES? isn't it required to be NO? thanks – eNeF May 19 '15 at 08:31
  • http://stackoverflow.com/questions/18376416/the-target-overrides-the-other-ldflags-build-setting-defined-in-pods-pods – Kirit Vaghela Jul 09 '15 at 12:36
  • This is not the Solution, all apps need support for 64 bit now. @chancyWu solution is the correct one. – heading_to_tahiti Aug 06 '15 at 00:36
  • @AdamG Is AT&T Speech to Text API still exists/operational? – Csaba Toth Mar 07 '18 at 00:47
52

I solved this problem by setting that:

ARCHS = armv7 armv7s

VALID_ARCHS = armv6 armv7 armv7s arm64

morisunshine
  • 780
  • 4
  • 7
50

I ran into the same/similar issue implementing AVPictureInPictureController and the issue was that I wasn't linking the AVKit framework in my project.

The error message was:

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

The Solution:

  1. Go to your Project
  2. Select your Target
  3. Then, go to Build Phases
  4. Open Link Binary With Libraries
  5. Finally, just add + the AVKit framework / any other framework.

Hopefully this helps someone else running into a similar issue I had.

valbu17
  • 4,034
  • 3
  • 30
  • 41
44

I also encountered the same problem , the above methods will not work . I accidentally deleted the files in the following directory on it .

Folder emplacement:

~/Library/Developer/Xcode/DerivedData/

enter image description here

Community
  • 1
  • 1
ylgwhyh
  • 1,588
  • 18
  • 21
26

Set Architectures to armv7 armv7s, Build Active Architecture Only to NO, for every target in the project, including every one in Pods

BabyPanda
  • 1,562
  • 12
  • 18
21

I fixed mine by checking the selected implementation files in the target membership on the right side. This is useful especially in dealing with extensions i.e. custom keyboards.

Target Membership

pkamb
  • 33,281
  • 23
  • 160
  • 191
jaytrixz
  • 4,059
  • 7
  • 38
  • 57
11

Here are some explanations why build_active_architecture is set to NO. Xcode now detects which devices you have connected and will set the active architecture accordingly. So if you plug a 2nd generation iPod Touch into your computer, Xcode should set the active architecture to armv6. Building your target with the above Debug configuration will now only build the armv6 binary to save time (unless you have a huge project you may not notice the difference but I guess the seconds add up over time).

When you create a Distribution configuration for publishing to the App Store, you should make sure this option is not set, so that Xcode will instead build the fat universal binary http://useyourloaf.com/blog/2010/04/21/xcode-build-active-architecture-only.html

auspicious99
  • 3,902
  • 1
  • 44
  • 58
Moaz Saeed
  • 1,006
  • 3
  • 10
  • 23
  • That is so unbelievably FUBARed! The output of XCode depends on what device you have connected to the build machine! – Matt Feb 04 '16 at 20:38
6

This might be related to libz.dylib or libz.tbd, just have to add it to your targets for the linking binaries, and try to compile again.

TonyTony
  • 1,344
  • 15
  • 23
6

You need to just remove arm64 from Valid Architecture and set NO to Active Architecture Only . Now just Clean, Build and Run. You will not see this error again.

:) KP

Kalpesh Panchasara
  • 1,730
  • 2
  • 15
  • 27
5

Solved after deleting the content of the DerivedData-->Build-->Products-->Debug-iphoneos

5

Following worked for me:

  1. Remove all pods cd ios && pod deintegrate
  2. Comment this line in ios/Podfile -> use_flipper!()
  3. Reinstall all pods arch -x86_64 pod install
  4. Run your app :) npm run ios

Environment:
Node version: 14.17.1
RN version: 6.0.0
OS: macOS BigSur m1

Deepak
  • 2,487
  • 3
  • 21
  • 27
4

I solved it by setting valid archs to armv7 armv7s and setting build active architectures only to YES in release and then doing a new "pod install" from the command line

Fabio Russo
  • 412
  • 6
  • 8
3

Given an iPhone 5s and not yet having received a 64 bit version of a third party library, I had to go back to 32 bit mode with the latest Xcode (prior to 5.1 it didn't complain).

I fixed this by deleting arm64 from the Valid Architectures list and then setting Build Active Architecture Only to NO. It seems to me this makes more sense than the other way around as shown above. I'm posting in case other people couldn't get any of the above solutions to work for them.

user938797
  • 167
  • 3
  • 15
3

I had the same problem after upgrading to Xcode 5.1 and fixed it by setting Architectures to armv7 armv7s

deko
  • 2,534
  • 3
  • 34
  • 48
3

Had been stuck on this issue the whole day.

I had multiple Schemes, it was compiling fine for Demo, Internal, Release - however Debug scheme just would not compile and was complaining about the libPods.a missing.

The solution was to go to the Project -> Target -> Build Settings and change "Build Active Architecture Only" to YES. Clean and build! Finally hours of head itching solved!

GameDev
  • 445
  • 7
  • 21
2

Setting -ObjC to Other Linker Flags in Build Settings of the target solved the problem.

Thomas G.
  • 1,003
  • 12
  • 27
2

As morisunshine answer pointed in right direction, a little tweak in his answer solved my problem for iOS8.2 .Thanks to him.

I solved this problem by setting that:

ARCHS = armv7

VALID_ARCHS = armv6 armv7 armv7s arm64

BUILD ACTIVE ARCHITECTURE ONLY= NO
Community
  • 1
  • 1
SandeepAggarwal
  • 1,273
  • 3
  • 14
  • 38
2
  1. Go to target Build Settings.
  2. set BUILD ACTIVE ARCHITECTURE ONLY = NO for both Debug and Release
  3. Build and run
Zia
  • 14,622
  • 7
  • 40
  • 59
2

This worked for me:

ios sdk 9.3

into your build setting of app.xcodeproj valid architecture: armv7 armv7s Build Active architecture : No

Clean and build , worked for me.

Shashank Saxena
  • 2,014
  • 17
  • 11
2

If you faced this issue on your Flutter project while building in Release mode (or Archive) check out my this answer: https://stackoverflow.com/a/61446892/5502121 Long story short:

  • set your build system to New Build System in File > Project Settings…
  • remove ios and build_ios folders
  • run flutter create . to init new ios module
  • run pod install
  • run flutter pub get
  • check your Xcode build config (it should be Release mode and General iOS Device)

and you're good to go

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

The following worked for me to get GPUImage compiling without errors on Xcode 5.1 for both the 64-bit simulator and retina iPad Mini, without needing to remove arm64 from the Valid Architectures list (which defeats the purpose of owning a 64-bit device for testing 64-bit performance).

Download the .zip folder from the GitHub page: https://github.com/BradLarson/GPUImage

Unzip, and navigate to the 'framework' folder. From here, add and copy the 'Source' folder into your Xcode project. Ensure 'Copy items into destination group's folder' is ticked, and that 'Create groups for any added folders' is also ticked. This will copy the generic, iOS and Mac header/implementation files into your project.

If you don't need the Mac files because you're compiling for iOS you can delete the Mac folder either before you copy the files into your project, or simply delete the group from within Xcode.

Once you've added the Source folder to your project just use the following to begin using GPUImage's classes/methods:

#import "Source/GPUImage.h" 

A few things to point out:

  • If you get an error saying 'Cocoa' not found, you've added the Mac folder/headers into your iOS project - simply delete the Mac group/files from your project and the warning will vanish
  • If you rename the Source folder (not the group in Xcode), use that name instead of "Source/GPUImage.h" in the #import instruction. So if you rename the folder to GPUImageFiles before you add to your project, use: #import "GPUImageFiles/GPUImage.h
  • Obviously ensure arm64 is selected in the Valid Architectures list to take advantage of the A7 64-bit processor!
  • This isn't a GPUImage.framework bundle (such as if you downloaded the framework from http://www.raywenderlich.com/60968/ios-7-blur-effects-gpuimage) so it may not the correct way to use GPUImage that Brad Larson intended, but it works for my current SpriteKit project.
  • There's no need to link to frameworks/libraries etc - just import the header and implementation source folder as described above

Hope the above helps - it seems there were no clear instructions anywhere despite the question being asked multiple times, but fear not, GPUImage definitely works for arm64 architecture!

1

This issue occurred for me after installing a pod via Podfile and pod install. After trying a bunch of different fixes I finally just imported the Pod manually (dragging the necessary files into my project) and that solved the problem.

Will Dennis
  • 1,045
  • 1
  • 10
  • 12
1

In my case, I had to look for

C++ Standard Library and make sure that the libc++ was the one selected.

Etienne Noël
  • 5,988
  • 6
  • 48
  • 75
1

For me, I use opencv 2.4.9 in xcode 7.2 for iOS and the errors above occurred, and I solve the errors by using the opencv through pod install rather than offline opencv framework.

You can have a try by adding the opencv pod text below and delete the offline opencv framework if you have used.

pod 'OpenCV', '2.4.9'

Chuyang
  • 71
  • 1
  • 7
1

None of the solutions fix this error in my case(Xcode 9), with TesseractOCRiOS. After hours of trial and error, I came up with a good solution. I just delete 'pod 'TesseractOCRiOS', '~> 4.0.0' in the Podfile, run pod install. And then, add pod 'TesseractOCRiOS', '~> 4.0.0' back to Podfile and run pod install again.

Bang! It works!

wzso
  • 3,482
  • 5
  • 27
  • 48
1

"The OPN [Debug] target overrides the OTHER_LDFLAGS build setting". This was the main issue. After adding $(inherited) in new line in other linker flags solved my issue. enter image description here

Mohsen mokhtari
  • 2,841
  • 1
  • 30
  • 39
1

in some case, if you define one more interface in a .h file, but did not implementation all these interface, this error occurred.

The linker can't found the implementation in .m file, so you need to implementation it in your .m file for every interface.

To resolve this error:

1.in .m file, supply the implementation for each interface. 2.rebuild

Michael Yang
  • 1,403
  • 2
  • 18
  • 27
1

If you use a .framework/.a writed by c++, where you invoke the c++ code, whice file need change to .mm file.

I losed half a day in that...

andaji
  • 71
  • 1
  • 5
1

I faced the same issue. My solution I found here: Why linker link static libraries with errors? iOS

Adding $(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME) to the library search paths fixed the problem.

Dmitry Soloviov
  • 491
  • 1
  • 5
  • 8
1

This linker error message suggests that the source file defining it is not marked as being part of your app target. Find that source file, and use the File property inspector on the right to check the target membership entry for your app target.

Solution: Select the file -> openFile Inspector -> see Target Membership -> check if unchecked target your running target

SaadurRehman
  • 622
  • 8
  • 20
1

This error consumed my whole day so thought of writing what really worked for me

  1. delete .xworkspace
  2. delete podfile.lock
  3. delete the Pods folder/directory

"DO NOT DELETE PODFILE"

After all this, CLEAN(OPTION + SHIFT + CMD + K) --> BUILD(CMD + B) --> RUN(CMD + R)

I hope this really works for you :)

nidhisoni
  • 51
  • 1
  • 6
0

I have facing the same problem after installing the AWS framework to overcome this issue,I have update the POD config file from your project which get created after installing AWS POD. Check config file as below

OTHER_LDFLAGS = $(inherited) -ObjC -l"Pods-AWSAutoScaling" -l"
Pods-   AWSCloudWatch" -l"Pods-AWSCognito" -l"Pods-AWSCore" -l
"Pods-AWSDynamoDB" -l"Pods-AWSEC2" -l"Pods-AWSElasticLoadBalancing" 
-l"Pods-AWSKinesis" -l"Pods-AWSLambda" -l"Pods-AWSMachineLearning" 
-l"Pods-AWSS3" -l"Pods-AWSSES" -l"Pods-AWSSNS" -l"
Pods-AWSSQS"-l "Pods-AWSSimpleDB" -l"Pods-Bolts" -l"Pods-FMDB" 
-l"Pods-GZIP" -l"Pods-Mantle" -l"Pods-Reachability" -l"Pods-TMCache" 
-l"Pods-UICKeyChainStore" -l"Pods-XMLDictionary" -l"sqlite3" -l
"z"-framework "Accelerate" -framework "AssetsLibrary" 
-framework "CoreLocation" -framework "Foundation" -framework
"ImageIO" -framework "Security" -framework "SystemConfiguration"
-framework "UIKit" -weak_framework "UIKit"
 OTHER_LIBTOOLFLAGS = $(OTHER_LDFLAGS)   

if your config file not working properly then Set your Other Linker flag to $(inherited)

Swapnil1156035
  • 361
  • 1
  • 11
0

If the architecture and linker settings look good, check your h files. My issue was the same error, but I had restructured the h files and I removed an extern statement. Other m files were using that variable, causing the linker error.

Nick
  • 2,735
  • 1
  • 29
  • 36
0

Adding "Security.framework" did the trick for me.

Eran Talmor
  • 1,918
  • 1
  • 12
  • 6
0

I know this is an old branch. However, the same problem started happening to me after migrating to the latest CocoaPods version (1.0.0) and trying to reinstall all pods. I encountered the "Missing symbols for armv64" linker error. Oddly enough, I solved it by performing the following steps:

  1. Remove all pods (pod init, pod install)

  2. Rewrite the podfile in a reversed order (instead of: pod "Mixpanel", pod "Intercom", I used: pod "Intercom", pod "Mixpanel" )

  3. Pod install

Reversing the order of the dependencies in the podfile and rebuilding the pods has solved the problem.

Arik Segal
  • 2,963
  • 2
  • 17
  • 29
0

My problem was that I already had some Facebook SDKs in my project (FBSDKLoginKit and FBSDKCoreKit).

I only needed one more SDK (FBSDKShareKit) and imported it, which thus gave "Undefined symbols architecture for arm64".

As the FBSDKShareKit is dependent on an updated version of FBSDKCoreKit, by updating the other frameworks, everything worked again.

Morten
  • 69
  • 1
  • 5
0

I had this issue with my 'umbrella framework' which when I was building the second level framework.

I solved this by changing my first level framwork's Build Scheme for 'Generic iOS Device'. I think this will change _CodeSignature, which I saw the difference when I pushing my whole 'umbrella framework' to GitHub.

Nijat2018
  • 863
  • 2
  • 10
  • 26
0

Put the library in the same folder of project, that works for me

Álvaro Agüero
  • 4,494
  • 1
  • 42
  • 39
0

In my case using dlib in IOS, I need to delete "inherited" from build settings/preprocessor macros.

Ozgur Sahin
  • 1,305
  • 16
  • 24
0

detail Hope can help you. I add framework and the problem has been resolved

0

Replacing -ObjC with $(inherited) in Other Linker Flags fixed my problem

Mithra Singam
  • 1,905
  • 20
  • 26
-1

This solution is the only thing that worked for me: go to CordovaLib settings and add arm64 to Valid Architectures.

idoshveki
  • 133
  • 1
  • 1
  • 6
-1

invoke pod update then remove pod 'ARCore' from your pod file, and invoke pod install again. then add pod 'ARCore' to pod file and invoke pod install again

Azade Rahmati
  • 135
  • 1
  • 5
-1

If you are using m1 (arm64) and you have problem you can run it in x86 mode:

  • Right click on xcode and tap on Get Info button
  • Tick the Open using Rosetta option

It will be slow but working.

Saba
  • 1,208
  • 14
  • 19