Mach-O Linker Error on Xcode 4.6 - ios

I have an iOS app on Xcode 4.6 and when I recently tried to build and run in the iPhone 6.1 simulator I got a "Mach-O Linker Error." It continued to say:
ld: 17 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Does anyone know how to solve this?
Thanks so much!

Just go to "Build Phases" -> "Compile Sources" and look for duplicate of classes.

Check if you have "*.m" files in your #import ! It appears that was my mistake...

Quit Xcode
Restart the System
Select Xcode -> Preferences -> Locations
In Locations, you will see 'Derived Data'. Click on the arrow icon right next to the path.
This will open a folder containing 'Derived Data', delete it.
Clean the Product and Run
if still not works then
Build Settings > Enable Bitcode > No

In my example, I declared
extern NSString const *keyString
in two different files. I renamed one of them and it solved my problem.

In my case it was constants.
NSString *const cellID = #"cellID";
This line was written in two .m files. After appending static keyword at the start the problem was resolved.
This issue can be recreated in a new project too. You would think that defining constants in the different .m files won't have any effect as they are private. But I don't know how the compiler is handling stuffs behind the scene. On top of that when you tap the issue from issue navigator it doesn't open up a page in the editor like it does for any other issue. Really frustrating.

I am not sure I can give you a solution but I will share an answer since the same happened to me on xCode 4.6 as well. I added a C class header and implementation file and included them in main. I then decided to delete that new C Class header and implementation. When I ended up adding a new c class/header again with the same name and function calls, I ended up with your error.
Frankly, this might be a bug. The only and fastest way I fixed it was to start a new project and pull all the classes in.

Make sure you don't have non-instant methods with the same name in multiple classes (So for example if I have two viewcontrollers that are pretty similar so to move quickly I copy and paste the code from one viewcontroller to the second and they both have methods called the same thing like: NSMutableString *filteredStringFromStringWithFilter(NSString *string, NSString *filter)) then the app gets confused which of those methods to use since they are both available, RENAME IT on the second class and change any calls to that method on that class and you've removed the confusion. Don't we all want things to be more clear!

If you want to change a value both in tow different class. Do remember to mark with static keywords.
or the clang will throw such error below without any value interpretation。
Apple Mach-O Linker Error
clang: error: linker command failed with exit code 1

When you refactor a class func you will also sometimes get this error. Just go to Product-> Clean and rebuild.

Build Phases" -> "Compile Sources" click the button "Validate Settings"
it's will fix your project

Related

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.

clang: error: no such file or directory when trying to run app

I have added flags in compile sources for janrain integration in my app.
When i m trying to run app or archiving build on that time i faced this error.
I already added that file to correct build path and its already contain within project.
Here i attached snaps of that error :
Can anyone please help me to solved this? Thanks in Advance.. :)
Go in your target compile sources and check its may be that you used the filename as compiler flag in ARC or you may used wrong compiler flags.
i hope its worked.
just check your compile sources its may that you give wrong flag for ARC or your file is not available with testtareget.
Just check your flags which u set in compile sources. Either its repeated or either its wrongly used.
This problem raised because of i am passing this class name to set in compile sources flag instead of -fno-objc-arc.
Check with your existing flags in your compile sources its may be that you used the filename as compiler flag.
Check once NPSAuthenticatedUser+Model is existing or not in your project. Whether it is in red color or what.
If it is red color remove and re add it if needed.
Please check this answer.
clang: error: no such file or directory: ASIAuthenticationDialog.m
Clean and Build your Project and then try again.
make sure you in the Other Linker Flags in case you use '$(inherited)', add only $(inherited) without the 2 ''
None of the possible solutions above worked in my scenario.
For a Swift project with Objective-C file(s) included make sure they are not added to the Build Phases -> Compile Sources section of your project's target.
I had a Swift project where after I dragged Objective-C files into the project the implementation files were added to the Build Phases -> Compile Sources section. Once I removed the Objective-C implementation files from the Compile Sources section my project worked happily once again.
This was using Xcode version 8.3 (8E162).

linker command failed with exit code 1 (use -v to see invocation) in Swift

I used Swift language in my IOS application project in Xcode6 Beta6 and then I had to work on it with another computer. Then I got this error:
"clang: error: linker command failed with exit code 1 (use -v to see invocation)"
This error is shown only different computers than the computer on which I opened my project at first. It does not give an error in the first computer (which I opened and started to the project)
I tried to clean, and delete the contents of DerivedData folder, but it gives me the same error again. Below this error, it also says that "file not found:" for inside of the DerivedData folder:
file not found: /Users/macbook/Library/Developer/Xcode/DerivedData/SihirliSayilar-gmmsqkhqgygosqeuqdiibnrjasbq/Build/Products/Debug-iphonesimulator/Project.app/Project
I looked the other titles for this issue, but none of them solve this problem.
Thank you for any help!
The fact that it's a linker error should point you into the right direction. Compilation errors usually mean an error in your syntax. Linker error means that although your source files have been compiled correctly, but when the time comes to be linked with other frameworks (system frameworks, or 3rd party ones), clang cannot find them in place.
Usually, this is because a 3rd party library is missing from your system, and your project depends on it, and although it can find the header files, it cannot find the actual library file to connect to. The fact that transferring your project to other computers is giving you problems, while at your computer compiles and links correctly also strengthens the assumption that probably it's a problem with the environment you are trying to compile with and you need to install something.
To find out more about the issue, go into Xcode, go into the report navigator, and you will see logs of all the builds you have made. Check the first one (which is the last build). Scroll to the bottom, and see exactly why it didn't compile. The most common scenario is that some symbol could not be found. Check in which library this symbol belongs, then install this library to your system.
I got same error you have mentioned. I have just clean the project and build it.
It worked!
You can clean the project in Product Tab and select clean. To build select build in product tab in Xcode.
I encountered the same problem and my solution is as follow:
Close the current project in xcode --->
Go to your project file and open the project by clicking the .xcworkspace file. Note: not the .xodeproj file.
Hope this helps!
In My case it worked like this:
-> Click on the project
-> Go to "General" tab
down there
-> Go to "Linked Frameworks & Libraries"
-> Click of the "+" button , you will find something like this -> Pods_yourProjectname.framework add it
-> Then add the Frameworks that you have added from there only!
-> "Command+B" (Build your Project) and the combination "Shift+Command+K" (Clean your Project)
-> Run your Application.
Simple Solution in my case:
Product -> Clean
and then:
Product -> Run
I faced this error when I opened .xcodeproj instead of .xcworkspace while using cocoapods dependency manager.
Make sure you are opening .xcworkspace.
I had the same error, and after digging through the logs I found the error "Duplicate Symbol"...
After a heap of searching I found that I had #imported a ".m" file instead of a ".h"
Maybe this might help someone.
In my case,
I faced the same clang error when I opened myproject.xcodeproj file instead of myproject.xcworkspace by mistake after installing cocoapods to my project.
it can be anything in your code, for me it was a problem with coredata classes?:
#objc(Attribute) // the problem
class Category : NSManagedObject{
}
changed to
#objc(Category)
class Category : NSManagedObject{
}
Set Host Application to your Project Target. Also, check the Allow testing Host Application APIs is turned on.
You might have to link file recently added. In My case files were not added but it got referenced in the project. The referenced file name must be appearing in red color. first, delete the referenced file, then you can right-click on the group add the file manually.

Apple Mach-O Linker Error Duplicate Symbols in Project Library

I modified my CoreData Data Set and added a couple of new classes to an error free iPhone App. Now when I try to compile I get this error:
Apple Mach-OP Linker Error Linker command failed with exit code 1 (use -v to see invocation)
duplicate symbol _OBJC_METACLASS_$_SchoolRecords in:
/Users/Yourself/Library/Developer/Xcode/DerivedData/.../YourProject.build/Debug-iphoneos/YourProject.build/Objects-normal/arm64/SchoolRecords.o
/Users/Yourself/Library/Developer/Xcode/DerivedData/.../YourProject.build/Debug-iphoneos/YourProject.build/Objects-normal/arm64/SchoolDivisions+Create.o
duplicate symbol _OBJC_CLASS_$_SchoolRecords in:
Objects-normal/arm64/SchoolDivisions+Create.o
duplicate symbol _OBJC_CLASS_$_SchoolRecords in:
/Users/Yourself/Library/Developer/Xcode/DerivedData/.../YourProject.build/Debug-iphoneos/YourProject.build/Objects-normal/arm64/SchoolRecords.o
I looked in the appropriate folder arm64 but see no duplicate files. So I have two questions:
1) Can I simply delete this folder hierarchy and start from scratch to see if that eliminates the problem?
2) How do I use the -v option to see invocation?
Thanks in advance for any hints.
Simple solution. While working on another project, I noticed Xcode's autocomplete was suddenly filling in .m rather than .h for #import statements. This had happened once on this project.
Changed import to .h and problem solved.
Lot of time spent on simple error.
XCode use some .m files twice (or more) with the same functions.
Try project clean
Try restarting XCode
Do you have deleted older files ? Look in "Project" -> "Targets" -> "Library search path" if there are folder pointing to older path.
Also look in "Targets" -> "Build phases" -> "Compile sources" and check for any file who can have duplicate functions

Linker command error: 'ld: symbol(s) not found for architecture i386'

I have an error at compile time. Seems to be weird. it worked as detail view application, but using single view doesn't seem to work.
this is the error details:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_RssArticle", referenced from:
objc-class-ref in RssXmlParser.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Try these steps:
Open your project in XCode.
In left side window/panel of XCode click on your project name on top.
Now select Target from right side panel of XCode.
Select Build Phases from right panel's top. (here other option will be Build Settings, Build Rules)
In the same panel open the "Compile sources", here check: are all the files (.m) listed? if not all files click on (+) sign in bottom to add (.m) files which is not in list
As per your error it seems RssXmlParser not there, add this and compile again
It will work fine now.
don't see anybody suggesting to go to terminal and go to the directory where the project is and run
xcodebuild -verbose
to see detailed error and just reading the error helps a lot of the time
I realized I had to use the .xcworkspace file instead of the .xcodeproj file.
Product -> Clean then Product -> Run :)
In my case, I mistakenly created a new subclass of UIView with .h and .c files instead of .h and .m files. Changing the extensions was easy, but I didn't think to change the contents of the .m files. So my .h files had
#ifndef My_Project_MPMyView_h
#define My_Project_MPMyView_h
#import <UIKit/UIKit.h>
#interface MPMyView : UIView
#end
#endif
and my .m files incorrectly had
#include <stdio.h>
When I changed my .m files to
#interface MPMyView : UIView
#end
#implementation MPMyView
#end
The linker error was fixed.
I solved the same issue because I created components as separate projects. After adding the folders to the main project, I forgot to delete the .plist, .string and extra main.m files from the imported component group directories.
Deleting these solved my issue because the app was obviously getting conflicting build commands...
I encountered this error due to duplicate filenames (I had created NSManagedObjectContext subclasses automatically in core data through the editor menu).
As of XCODE 5.0, just quit and restart and xcode should recognize this and fix it for you if you click on the yellow warning in the left hand pane
A similar error just happened to me on Xcode 6.4. Seems like an Xcode bug.
My fix was to go to the ".o" file that caused the error, uncheck and recheck target memberships that you need.
I think it might be that you are trying to create two different .C file (with main function) in one project. C only allows you to have one main entrance every project.
I don't know how it worked.But i simply closed the xcode and open again by clicking xcworkspace file and worked for me. you may try hopefully this can solve your problem thank you.
Hold down alt .
On the top toolbar go to
Product > clean build folder
Press "clean build folder" and wait for it to build and run.
It should resolve any errors in the build file.

Resources