How to solve 'duplicate symbols for architecture arm64' error? - ios

When I try running my Xcode Project it fails with an error stating that I have duplicate symbols. Below is the way I sovled this error. Hope to help you~
The error info:
From the error info I found that WPBuySkinAlertView maybe the duplicate class.So I seach the file in the project.
There are two WPBuySkinAlertView files in the project.
So, next time when you come with this error, check your project according to the error info, find the duplicate classes and remove the one.

Select Proiect ===> Target ===> Build phase ==> Compile source search WPBuySkinAlertView this name you will see 2 file in search result remove one from them

If this error occurred right after installing a new pod, run pod update. I suspect that the new pod I installed actually installed some of the same dependencies as a previous pod, so there was a duplicate. pod update fixed it for me.

As I found out, multiple causes can lead to this error. I had 2 files containing #main and that is non logical.
In the docs it says:
Apply this attribute to a structure, class, or enumeration declaration
to indicate that it contains the top-level entry point for program
flow.
This was my mistake:
File1.swift
import SwiftUI
#main
...
File2.swift
import SwiftUI
#main
...

In my case I had an issue with one of my pods (cocoa pods) and needed to comment it out, re-run it without it and everything seemed fine. I had recently changed the revision for SDWebImage in my Podfile.

Related

command libtool failed with a nonzero exit code [duplicate]

When I try to build my app with Xcode, an error interrupts the build process:
Command CompileStoryboard failed with a nonzero exit code
Sometimes, it shows this error instead:
Command CompileSwift failed with a nonzero exit code
I have New Build System turned on.
What can I do to fix this?
Closing Xcode for me didn't have an effect. Instead, I cleaned the project using CommandShiftK.
I also found another reason: I had a storyboard reference to another storyboard which I had removed. The quick fix was deleting this.
I also facing same issue in xcode 10 and tried all the solutions provided but nothing working.
Then I deleted all the files and folders of the following folder :
~/Library/Developer/Xcode/DerivedData
and it worked like a charm.
When you stop building a project when the compiler is in the middle of something "important", this error could appear. In that case, building the project again and letting it finish normally makes this error disappear.
This is a known issue with Swift 4.2 and Xcode 10. I found an article here that fixed it for me: https://github.com/Yummypets/YPImagePicker/issues/236
In short, go to your projects build settings, and add a user defined setting named SWIFT_ENABLE_BATCH_MODE and set its value to NO.
Previously, I tried each of the methods suggested here (rebuild, exit Xcode, clean and rebuild, purge Derived Data files). None of them worked.
Once I added the user define build setting per the article, Swift then told me the true error. In my case, it was a missing }, but it could be any number of problems.
I encountered this error when I was upgrading my project from Swift 4 to 5.
I first updated all my pods to their latest versions. When I built, some pods showed this error.
The following steps resolved this issue for me:
Removed all pods from Podfile
Executed pod install to remove all installed pods
Executed pod deintegrate to remove support for CocoaPods
Deleted Podfile.lock and .xcworkspace from my project so no
CocoaPods anymore
Now my project is a pure Xcode project
Opened my project from the regular .xcodeproj file
Changed Swift Version of my project to Swift 5
Cleaned the project (cmd+shift+K)
Quitted Xcode
Restored all pods to my Podfile
Executed pod install to reintegrate CocoaPods and add my pods
Opened the project from the .xcworkspace file
Cleaned and rebuilt
Some old pods that were still using Swift 4.0
(SlideMenuControllerSwift in my case) were set to Swift 5.0, caused
many build errors in their code. I corrected it back to Swift 4.0
by opening the Pods project and selecting its target.
Cleaned again, rebuilt.
Now I have only errors in my own project code related with difference in Swift version I made. My job now is to fix them.
This error happened to me when I forgot to change entity Properties before creating NSManagedObject subclass. Solved by:
delete Entity+CoreDataClass.swift and Entity+CoreDataProperties.swift.
under "class" of the entity model inspector, change "module" to Current Product Module and "codegen" to Manual/None.
recreate the NSManagedObject.
I had the error Command LinkStoryboards failed with a nonzero exit code, and found that I was using a reference to a non-existent storyboard. I had recently changed the name of a storyboard file, so changing the reference from the 'old' name to the 'new' name solved it for me.
You may not have exactly the same error as me, but an easy way to find a more detailed explanation of the error is to:
Show the issue navigator (while the build time error is showing)
Click the error:
Then, you should see more about your error:
I hope this helps. Please, I am aware that I am answering from experience of a different error than this question was asked about, but I believe this advice should help you conquer similar problems!
For me cleaning the project (Command + Shift + K) and restarting xCode worked for me
If you have multiple targets, where two or more targets have files with the same name, check the target membership of those files in Files inspector. The error occurs when multiple instances of the equally named file have set the target membership for the same target.
Since this issue looks to have dozens of possible solutions and the root cause could be very vague, I'll throw my situation into the ring. Half of my pods were failing with some sort of CompileSwiftSource failure, but only on archive. I was still able to build for device and simulator just fine. I tried a lot (if not all) of the solutions suggested here with no luck. One of the pods had a slightly different error before the CompileSwiftSource error so I went to updating and trying to fix that single pod. It was the Cache library for iOS which hadn't been updated in a while. There was a fork that resolved the issue with updating to Xcode 10.2 that I was able to update to and after that, all of the other issues took care of themselves. So look for a single outlier in your pods if you're getting a bunch of them erroring out and start there.
Switching to the legacy build system fixed the issue for me
In my case, I was clean build folder then restart my mac then it's work.
I had the JSONwebtoken pod installed and that was causing issues. I needed to delete the CommonCrypto folder that is in the JSONWebtoken pod folder. Here is a ->link<- explaining the issue. This started happening in Xcode 10.
In my case it was about having a file named Location. after some digging I find out that it was about having two file with the same name (weird). Cause I don't, however, it's been solved by removing the file and adding another file with a different name.
filenames are used to distinguish private declarations with the same name
This can also occur when you have two swift files with the same name. For example, two ContentView.swift files
In my case, I used too complicated initializations inside a class extension. It suddenly broke my build.
class MyClass { }
extension MyClass {
static var var1 = "", var2 = "", var3 = "", var4 = "", ...., var20 = ""
}
Resolved:
class MyClass { }
extension MyClass {
static var var1 = "",
static var var2 = "",
static var var3 = ""
static var var4 = "", ....,
static var var20 = ""
}
In my case it was empty assets catalog, when I delete it everything was fine again.
Command CompileSwift failed with a nonzero exit code
This error happens when you are migrating your code from Xcode 9 to Xcode 10+. It due to any class name is conflicting with existing apple classes. For Example: State, Event etc.
So first change the class/structure name if any existing in your code like "State" to "StateDetail"
If Info.plist is added in target, remove tick mark from it so it will not copy app bundle (Latest Xcode10 security reason).
Select Info.plist file and uncheck under "Target Membership" in right side Identity inspector
And build code again!!!
In my case, the problem was that I assigned a .swift class to the viewController in the storyboard, while the project was Objective C.
I tried a lot of the options discussed here.
Delete and reinstall pods
Clean Build Folder
Delete Derived Data
Add SWIFT_ENABLE_BATCH_MODE and set its value to NO
Restarting Xcode and Recompiling
Restarting iMac and Recompiling
set Compilation Mode to Incremental
Changed build settings: SWIFT_COMPILATION_MODE = singlefile and SWIFT_OPTIMIZATION_LEVEL = "-O"
Nothing worked. I'm using Xcode Version 11.0 beta (11M336w).
Finally I downloaded a fresh copy and replaced the one I had previously installed. It was the same exact version. That did the trick.
I got this error while trying to run my unit tests in a submodule. What I have done is:
Change the simulator => Clean the project => Build the project => Run unit tests.
After this, my unit tests ran without any issue.
I have the issue like that and my solution is change a little thing in Build Settings:
SWIFT_COMPILATION_MODE = singlefile;
SWIFT_OPTIMIZATION_LEVEL = "-O";
it work to me
Alright, I was having the same problem with Xcode 10. I usually use a storyboard for every view, that way if someone is helping it's easier to fold code in. I needed to make one of the view on one storyboard the initial view Controller.
In my case it was renaming a file to an existing file in other folder(Group) by mistake, just rename it to what it was then the error disappeared
The targets should be specified with related data such as appicon
For me the problem was that on my Podfile I didn't put use_frameworks!. I just uncomment that line, run pod install on the terminal again. And it got fixed.
It was commented since the app was entirely made on Objective-C. Since the app now uses Swift I had to make that change on the Podfile
I had the same error Restarting Xcode and Recompiling Fixed the issue for me.
I got the same error when linking separate storyboards. The error, "Command CompileSwiftSources failed with a nonzero exit code." is shown because I simply forgot to set the view controller inside the second storyboard that I am linking as 'an initial view controller'.
In my use case I had used the function "Refactor to Storyboard" in Xcode 13. It created the new refactored story board fine but failed to add it to bundle resources.
So my fix was to:
Select the target project in Xcode Navigator
Choose the build phases tab
Expand Copy Bundled Resources to see if new storyboard was added. If not, just add it to the list and rebuild.
My app was having Notification Service Extension, and was using Xcode 11. The Extension doesn't have anything to do with pods.
After 1-2 years, I have taken that project into my new m1 chip mac with Xcode 13. But the compilation was failing and showing me the error in pods.
I tried to remove and add all pods, tried clean etc all possible available answers available on internet. Almost spent 4-5 hours to make it run, but nothing worked.
Final Solution that worked:
I removed, notification service extension from the project, its target etc too. And then tried to run the app. Amazingly it worked. After that, i added that extension again(by creating new extension and putting the same code again), and everything is working perfectly fine.
I am still surprised that, was that issue with extension or with pods. But finally it worked for me.
Hopefully, this answer might resolve someone's issue and you can save enough time.

Cannot load module 'Snapkit' as 'Snapkit'

I've tried every way of installing 'Snapkit' but so far I'm not having much luck.
I'm using the following:-
Xcode 8.3.3
So far I've tried following all the documentation online to solve the issue, however it still isn't working. Including following the steps here.
The current error message is "Cannot load module 'Snapkit' as 'Snapkit".
Although previously the message was no such module 'Snapkit'.
Typo in case - SnapKit, not Snapkit.
import SnapKit
I had the same error recently. That's why I saw your question. I rebuilt and ran the app. After the build is finished it now recognizes SnapKit )). If you opened it through workspace and if the contents of the pod file are ok, then it should open. Try building the project and type SnapKit after it.
Please ensure if you're using Cocoapods as your dependency manager that you're loading the Xcode WorkSpace and not the project file. Otherwise try cleaning the project and rebuilding.

Linker Command failed with exit code 1 (use -v to see invocation), Xcode 8, Swift 3

I can't get rid of this error!
I have tried all sorts of things like clearing Derived Data(Preferences->Locations->click gray arrow to open Derived Data folder in Finder->right-click, move to trash), cleaning the project(CMD+Shift+K or Product->Clean), updating carthage and dependencies, checked other answers on StackOverflow (mostly adjustments in Build Settings/Phases), and recloned the app from github, etc.
The same project works on my collaborators computers..
EDIT:
From the current top-rated answer, I was able to debug a little further...I am still not sure how to fix though. It looks like I have something in the project twice? I looked and can't find anything showing up twice!
Here's a picture of the log:
i was facing same issue today in xcode 8 version 8.3.2
right click on issue --> reveal in log
then you are able to check what is causing that issue
Maybe you installed a pod file and you are still trying to build from the .xcodeproj file instead of .xcworkspace
the only thing that worked for me was to run pod deintegrate and pod install
did you try a clean? cmd + shift + k
Okay...So here is what solved my problem...
in App Delegate File:
#import "AppDelegate.h"
#import "DarkSkyAPI.h"
//#import "Credentials.h"
I had imported Credentials.h already in the DarkSkyAPI.m file in my project. Commenting out the extra import made the error go away!
Some things to mention and maybe help anyone in the future. #umairqureshi_6's answer did help me along the process, but did not solve it. He led to where I was able to dig out the info. I kept seeing AppDelegate and DarkSkyAPI files showing up in the error log and the information it was pulling from Credentials file was causing the error. I knew it had to be in one of these 3 files, so I immediately checked imports, because I remembered hearing that the .h carries all the imports from its .m file. Boom!
I k now the question has already been answered. But if this helps somebody save some time :
I had the same error. I checked everything to find a very small and stupid mistake from my side. I imported a core data ManagedObject custom file in a view controller of my project. I accidentally imported the .m file instead of the .h file which was causing the duplicate symbol in architecture error (linker command failed) because my .m file of properties class imports the .h file of core data class and hence causing duplicate import.
So just check if u have imported the right files before you try multiple solutions.!
A lot of solutions are mentioned above. No one worked for me(but please try above first).
Select Project -> Select Target -> Linked Framework and Libraries -> Add all pod libraries . (remove if they exist in embedded binaries)
Now remove these from Framework Folder in left file explorer of xcode.
This solved my issue.
Select the project-> Build Phase->Link Binary with libraries and add all pod libraries.
I had the same problem using Carthage for dependencies.
Just go to Select Project -> Build Settings -> Search for Enable Bitcode -> If it is selected to Yes, select No.
That solved this problem for me.
In my case the reason of the error is library which was linked two times.
I use react-native so it was linked automatically using react-native link and manually in xcode.
I had same problem.
The cause was that I declared same global variable in 2 files. So it was showing same error saying 2 duplicate symbols.
The solution was to remove those variables.
For any one having this issue with Flurry framework. This is what fixed my issue.
For me the issue was that i had imported the following files but never used them.
"libFlurryTVOS_9.2.3"
"libFlurryWatch_9.2.3"
So all I had to do was go to project target settings and remove these 2 files from the "Linked framework and libraries" section and the problem was solved.
Make sure the Find Implicit Dependencies checkbox is checked.
(Product -> Scheme -> Edit Scheme -> Build -> Find Implicit Dependencies)
I was testing the Sparkle framework with CocoaPods.
Sadly, I put pod 'Sparkle', '~> 1.21' in the PodFile in the wrong place. I put it underneath Testing (for unit tests).
Once placed in correct spot in PodFile, everything's fine.
I just had to do import Foundation!
I was using Kitura for Swift server side and kept forgetting this!
Here is my problem and solution:
I removed two files from the source code using source tree(Version controller). After applying the diff, that contains the two classes I removed, Xcode didn't add it automatically. So I got linker error.
I manually added the files, by right click on group name and select "Add files to ". Now my error got resolved.
If anyone faced the linker error regarding class file, then try to add it manually.
Did not have this problem when I built and ran on my own device. Only had this problem with simulators. I just simply restarted my computer and ran it. It worked.
In my case I have change the Target name in my Podfile So it's create the same Error for me.
Solution
Just go project-> Build Phase->Link Binary with libraries Remove the old FrameWorks by click on minus button(-) And clean and Run again. It's work me.
Remove Unwanted .framework.
The other answers didn't work for me so here I share my solution in case it might help somebody else:
My problem was that I was configuring the Podfile of my XCode-Project for the wrong platform. Changing "platform :ios" at the beginning of my Podfile to "platform :macos" worked for me to get rid of the error.
I had the same problem. If you are checking out any github project, then instead of using git clone, use git lfs clone, as sometimes, some large files are not properly cloned by using git only. Also, make sure your bitcode is disabled.
For me, the gem lock file was specifying an older version of cocoapods than the one I had installed. I had to re-branch and run bundle exec pod install instead of pod install
It seems like the issue is different for most of us, and the error message has decent info. In my case, the Deployment Target was set to 10.13 by the export MACOSX_DEPLOYMENT_TARGET=10.13 line, but I was running 10.14. So I had to switch my Deployment Target to 10.14 in General > Deployment Info, in order for the ITLibrary-related symbols to be available again.
cd /Users/foo/src/scrobble/macos/itunes-scrobble
export MACOSX_DEPLOYMENT_TARGET=10.13
... SNIP ...
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_ITLibMediaItem", referenced from:
objc-class-ref in AppDelegate.o
"_OBJC_CLASS_$_ITLibPlaylist", referenced from:
objc-class-ref in AppDelegate.o
"_OBJC_CLASS_$_ITLibrary", referenced from:
objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
In my case, I was producing multiple products from the same project. For one of the products, the main.m file imported a header file from another folder under the same project. But that file was not included in "Complied Sources" under "Build Phase". This caused a linker error.
After carefully comparing the "Build Phases" settings for a product that could be built successfully, I realized that the .m file of the header needs to be included in the list of "Compiled Source". My issue was resolved after adding that file. Attaching a picture for clarity. The highlighted file had to be added.
One of the reasons of this problem might be "Build Active Architecture Only". You need set to true.
IOS version in build phases of pod(in xcode) and ios version in pod file should be same (Try with 9.0)
Ok, I had the same problem just today and started googling it, when I came across this thread. I haven't finished reading the question when the answer struck my mind:
I declared a class with an empty constructor
class MyClass{
MyClass();
void func_one(){
// code
}
void func_two(){
// code
}
~MyClass(){
cout << "Deleting object" << endl;
}
};
Then I thought why not terminating (not sure if I'm correct with word selection here, but who cares) the constructor of my class with curly braces ({}). So I did:
class MyClass{
MyClass(){}
void func_one(){
// code
}
void func_two(){
// code
}
~MyClass(){
cout << "Deleting object" << endl;
}
};
The problem eliminated, my code started working perfectly.
I know, the good practice is to investigate the issue and find the real cause, but this worked for me.

'Use of unresolved identifier FIRStorage' (Swift - Xcode 7.3.1)

I've been using Firebase SDK for some months but never got an issue. This time I can't get the storage to work even if I did all the steps correctly. I have the correct podfile and when I do the install I can see it downloads the correct framework and I can see the framework listed in my project, too.
I tried to change 'import Firebase' to 'import FirebaseStorage', it recognizes the framework and doesn't give any error on the import, but I still get the same error.
Edit: I know how to show images in my question but I can't do it because I must have at least 10 reputations.
Edit 2: I resolved and I'm waiting to accept my own answer.
Ok, that project was not working so I created a new project with the same podfile and all went well. Maybe it was a naming conflict because stupidly I named my first project FirebaseStorage.

Upgraded Firebase - Now Getting Swift Compile Error

I upgraded Firebase yesterday and now am having a very unusual problem. When I run the simulator, I get a swift compile error "Segmentation fault: 11" The are hundreds of lines of code describing the error, but they are absolutely no help. From the error, the only thing I see that might be giving clues is at the bottom. It says:
1. While loading members for 'ProfileTableViewController' at <invalid loc>
2. While deserializing decl #101 (PATTERN_BINDING_DECL)
3. While deserializing decl #2 (VAR_DECL)
Oddly, the errors I just typed above are not consistent. The view controller mentioned rotates between the three view controllers where I am using Firebase.
To try to solve the problem, I commented out all of the code in the ProfileTableViewController class, but I still got an error referencing that view controller. The only code running in the view controller was:
import UIKit
import Firebase
import FirebaseDatabase
(I'm also using FirebaseAuth in other view controllers).
What does work to fix the problem is to hit "clean", restart xcode, clean again on launch and then run the program. Everything will work fine unless I make any changes to the code in the program. Even if all I do is add a comment, the error will reappear.
I don't want to have to close xcode and restart every time I write a couple lines of code, and I am worried that I will run into problems when uploading to the app store.
I am using XCode 7.3.1 and my deployment target is 9.3
Any insight you can give is greatly appreciated! Thank you!
I was able to figure it out! My Cocoa Pods were not up to date. As soon as I went back and installed the latest Cocoa Pods in the terminal, then updated the podfile for this app, this error disappeared.
Process:
Open terminal
sudo gem install cocoapods
(Cocoapods update) In terminal navigate to app folder, then:
open -a xcode podfile
If needed, make changes in podfile. I didn't need to make any changes. Save and exit.
In terminal
pod update
Open the .xcworkspace file and ta da!
I was also pulling my hair out with this issue for some time.
I tried Eric Duffett's answer but without luck.
I figured out it was an issue with the FirebaseAuth. What I did was this:
Remove FirebaseAuth from Podfile
Update pods with pod update
Download Firebase frameworks from their site (at the bottom)
Follow README file to import FirebaseAuth manually in the project (need to import FirebaseAuth.framework and GoogleNetworkingUtilities.framework)
Clean - Build and no more segmentation fault 11 error
Hope this will help someone.
This is/was really driving me berserk.
This code causes the aforementioned crash:
func ref() -> FIRStorageReference {
return FIRStorage.storage().reference()
}
If I just use it in a function everything works:
FIRStorage.storage().reference().dataWithMaxSize(...
Took hours to figure this out. The error message points to somewhere else. This was probably the most frustrating debugging experience in my entire career.
In your podfile you can try to uncomment use_frameworks!
use_frameworks!
pod 'Firebase'
pod 'Firebase/Database'
pod 'Firebase/Auth'
Then run 'pod update' in the terminal. Restart your Xcode project.
This did it for me after struggling for two days with the Segmentation fault 11
Deleting DerivedData and ModuleCache, then Clean>Build worked for me.
I also had this problem with Firebase.
Xcode would complain on particular class. Just like your "ProfileTableViewController"
What I did to solve this was:
Comment all Firebase related imports in that class -> Clean -> Build (Obviously got some errors) -> Uncomment -> Clean -> Build succeeded
I figured out a different solution that worked for me. I had a few custom functions that returned Firebase-specific variables like FIRUser to files that didn't have import Firebase or import FirebaseAuth at the top. I like keeping my data service methods in a separate file, so I just changed the functions so that they returned Strings, such as FIRUser.uid, instead. This FINALLY got rid of the compiler warnings/crashes for good.
The problem for me occurred when I was explicitly setting the types of the completion block parameters for setValue.
FIRDatabase.database().reference(withPath: "test").childByAutoId().setValue("test1") { (error: Error?, ref: FIRDatabaseReference) in }
Everything works fine when the types for error and ref are removed.

Resources