[objective-c] Apple Mach-O Linker Error when compiling for device

I've just upgraded to xcode 4.0 and I can no longer deploy to iPhone, I get a Apple Mach-O Linker Error, it still works for the simulator though.

    Ld /Users/yveswheeler/Library/Developer/Xcode/DerivedData/iParcel-fkeqjcjcbbhjwhdssjptkdxzzzxh/Build/Intermediates/iParcel.build/Debug-iphoneos/iParcel.build/Objects-normal/armv7/iParcel normal armv7
    cd /Users/yveswheeler/iParcel
    setenv IPHONEOS_DEPLOYMENT_TARGET 3.2
    setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/g++-4.2 -arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk -L/Users/yveswheeler/Library/Developer/Xcode/DerivedData/iParcel-fkeqjcjcbbhjwhdssjptkdxzzzxh/Build/Products/Debug-iphoneos -F/Users/yveswheeler/Library/Developer/Xcode/DerivedData/iParcel-fkeqjcjcbbhjwhdssjptkdxzzzxh/Build/Products/Debug-iphoneos -filelist /Users/yveswheeler/Library/Developer/Xcode/DerivedData/iParcel-fkeqjcjcbbhjwhdssjptkdxzzzxh/Build/Intermediates/iParcel.build/Debug-iphoneos/iParcel.build/Objects-normal/armv7/iParcel.LinkFileList -dead_strip -all_load -ObjC -lxml2 -miphoneos-version-min=3.2 -framework UIKit -framework CoreGraphics -framework QuartzCore /Users/yveswheeler/Library/Developer/Xcode/DerivedData/iParcel-fkeqjcjcbbhjwhdssjptkdxzzzxh/Build/Products/Debug-iphoneos/libThree20.a /Users/yveswheeler/Library/Developer/Xcode/DerivedData/iParcel-fkeqjcjcbbhjwhdssjptkdxzzzxh/Build/Products/Debug-iphoneos/libThree20Core.a /Users/yveswheeler/Library/Developer/Xcode/DerivedData/iParcel-fkeqjcjcbbhjwhdssjptkdxzzzxh/Build/Products/Debug-iphoneos/libThree20Network.a /Users/yveswheeler/Library/Developer/Xcode/DerivedData/iParcel-fkeqjcjcbbhjwhdssjptkdxzzzxh/Build/Products/Debug-iphoneos/libThree20Style.a /Users/yveswheeler/Library/Developer/Xcode/DerivedData/iParcel-fkeqjcjcbbhjwhdssjptkdxzzzxh/Build/Products/Debug-iphoneos/libThree20UI.a /Users/yveswheeler/Library/Developer/Xcode/DerivedData/iParcel-fkeqjcjcbbhjwhdssjptkdxzzzxh/Build/Products/Debug-iphoneos/libThree20UICommon.a /Users/yveswheeler/Library/Developer/Xcode/DerivedData/iParcel-fkeqjcjcbbhjwhdssjptkdxzzzxh/Build/Products/Debug-iphoneos/libThree20UINavigator.a -framework AddressBook -lz.1.2.3 -framework Foundation -framework CFNetwork -framework MobileCoreServices -framework SystemConfiguration -framework MessageUI -framework AudioToolbox -o /Users/yveswheeler/Library/Developer/Xcode/DerivedData/iParcel-fkeqjcjcbbhjwhdssjptkdxzzzxh/Build/Intermediates/iParcel.build/Debug-iphoneos/iParcel.build/Objects-normal/armv7/iParcel

arm-apple-darwin10-g++-4.2.1: /Users/yveswheeler/Library/Developer/Xcode/DerivedData/iParcel-fkeqjcjcbbhjwhdssjptkdxzzzxh/Build/Products/Debug-iphoneos/libThree20.a: No such file or directory
arm-apple-darwin10-g++-4.2.1: /Users/yveswheeler/Library/Developer/Xcode/DerivedData/iParcel-fkeqjcjcbbhjwhdssjptkdxzzzxh/Build/Products/Debug-iphoneos/libThree20Core.a: No such file or directory
arm-apple-darwin10-g++-4.2.1: /Users/yveswheeler/Library/Developer/Xcode/DerivedData/iParcel-fkeqjcjcbbhjwhdssjptkdxzzzxh/Build/Products/Debug-iphoneos/libThree20Network.a: No such file or directory
arm-apple-darwin10-g++-4.2.1: /Users/yveswheeler/Library/Developer/Xcode/DerivedData/iParcel-fkeqjcjcbbhjwhdssjptkdxzzzxh/Build/Products/Debug-iphoneos/libThree20Style.a: No such file or directory
arm-apple-darwin10-g++-4.2.1: /Users/yveswheeler/Library/Developer/Xcode/DerivedData/iParcel-fkeqjcjcbbhjwhdssjptkdxzzzxh/Build/Products/Debug-iphoneos/libThree20UI.a: No such file or directory
arm-apple-darwin10-g++-4.2.1: /Users/yveswheeler/Library/Developer/Xcode/DerivedData/iParcel-fkeqjcjcbbhjwhdssjptkdxzzzxh/Build/Products/Debug-iphoneos/libThree20UICommon.a: No such file or directory
arm-apple-darwin10-g++-4.2.1: /Users/yveswheeler/Library/Developer/Xcode/DerivedData/iParcel-fkeqjcjcbbhjwhdssjptkdxzzzxh/Build/Products/Debug-iphoneos/libThree20UINavigator.a: No such file or directory
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/g++-4.2 failed with exit code 1

This question is related to objective-c iphone xcode xcode4

The answer is


My specific error was:

ld: entry point (_main) undefined. for architecture armv7

Which should have been obvious, but it's because main.m was not include into Compile Sources under Build Phases


I got the same issue when i export FMDB module in xcode 4.6. Later i found a fmdb.m in my my file list which was causing this issue. After i removed from the project it works fine


You may need to update your build settings.

Verify the iOS target version and the processor architectures, as you may not have the old SDKs with XCode 4.

You may see «Missing SDK» on the build settings. Change that to whatever applies.


If you use Xcode 7 or later just do a product -> clean. This worked for me.


The solution of this problem is very simple Just go to the directory where the project installed and open the file with extension ".xcworkspace"

That will solve the problem .


In my case the problem was having different architectures specified under different targets. I was building my application target with armv6, armv7 and cocos2d with Standard (amrv7). Go into build settings and make sure your architectures agree for all targets.


I encountered with this problem to figure out that I have two references in my XCODE project. Just delete the other reference. Hope this helps


I had exactly the same problem just because I had two same constants in different classes. You also can have this problem if you import .m file not .h file


Changing "Build Active Architectures Only" to Yes in CordovaLib.xcodeproj -> Build Settings did the trick for me. earlier the app was running on simulator, but not on the device.


For me it was accidentally importing an implementation ".m" file instead of the corresponding header ".h" file. As soon as I caught that the project build was back to normal.


in my case i just moved the .h .m file from one folder to other folder and that folder was not exsisting behind. so i created folder first on finder and then moved the file on finder and then add that folder and remove the reference of moved filed to other folder from project it stopped giving me error


Here is permanent solution.Generally overwriting project may cause this prolems.Try this method.

-UPDATE - Clang error - Mach-O Linker error

In some case error log window displaying .xctest error, to fix it

-> Select your project

-> Beside this(just before General tab) select your projectTest file from dropdown

-> There is one option (like ProjNameTests)

-> In Host Application, select your project from dropdown only if it show custom

DONE!

enter image description here

Old method deleted


I accidentally added two copies of the same subclass of a UITableViewController. Removing one of the sets of files cleared up the error.


Code Signinig!!!

I had this issue too - "linker command failed with exit code 1 (use -v to see invocation)"

my problem was I tried to run the app on a real device, and I forgot to configure the Code Signing section in the Build Settings tab.


In my case I had duplicated a class file! Found it by using the bottom search field at the right side bar of Xcode, so to solve it remove reference of one of them


My fix for my same problem: Adding the "other linker flags" in "Project" and not in "Targets". So, I moved it to "Targets", it shouldn't be in "Project".


Please go to your workspace setting and make the following changes:

Workspace Setting:
   Build System:
     Legacy BuilPer-User


 Per-User Workspace
  DerivedData:
    Workspace relative location



Build System 
    Use User Setting

If you have defined NSObject with the same name like:

NSObject *notUniqueObj;

even in 2 different files ( if you are importing one in another ), it will give you an error. Give different names for those.


For me was architectures fault when running on device in XCode 4.5.x.

XCode 4.5 doesn't support armv6 any more, so my fix was:

I just edited all targets in all libraries (three20Core, three20Common, etc.) and libThree20: in build settings have chosen only armv7 and armv7s in "Architectures" and "Valid Architectures"


None of these answers helped me. Then I tried to reinstall Cocoapods:

pod deintegrate

pod install

Problem solved!


One possibility: Turn on "Dead code stripping" in the Xcode 4 build settings.

Another possibility: It could be that you switched to using LLVM for some framework that was previously using GCC. Moving back to GCC (or LLVM GCC) may get rid of those warnings.


I had to make sure my framework was built with a Simulator selected in order to build my project with a simulator (my project of course is using the framework). Same goes for building on my iPhone everything has to be in sync not sure why but it fixes the issue.

I hope this helps someone.


I was able to fix this error by editing "Library Search Paths"

It cropped up in the first place because I had moved a couple folders around, and that ended up giving my build settings two different search paths because they are are automatically added to your build settings when you link a library/framework, but they are not always removed.

So if you move a linked library/framework to a different directory and re-link it, you'll have to manually edit the search path.

You might be able to dodge this by removing the library/framework before moving it, but I haven't tested that.


I had the same problem and the issue was that I have accidently imported a .m file instead of .h in an implementation file - hope it helps


Not sure if it's related, but seeing that you're running some three20 libraries, you may want to check this post on their website: http://three20.info/article/2011-03-10-Xcode4-Support


I had this same problem just a minute ago. which lead me here, which wasn't of any help. But I figured out what was the problem and fixed it. the problem was that in my header file i had declare one instance of the struct class named trig_node[SIZE]

my header...

struct TrigNode
{
    float msin;
    float mcos;
    float mtan;
}trig_node[SIZE];

and in my .cpp file i have a function that access this instance and return the answer.

float cos_table_(float deg)
{
    uint n = ((SIZE/DEGRE)*deg);
    return trig_node[n % DEGRE].mcos;
}

which is what as causing my linking error. So, to fix that i place the instance of the trig table class "trig_node[SIZE]" in the .cpp file which cleared the error. so now the new fix looked something like this

my header...

struct TrigNode
{
    float msin;
    float mcos;
    float mtan;
};

my .cpp file trig_node[SIZE]

float cos_table_(float deg)
{
    uint n = ((SIZE/DEGRE)*deg);
    return trig_node[n % DEGRE].mcos;
}

I fixed it by changing Mach-O Type under linking section on the Build settings from Nothing to Executable.


I was accidentally trying to compile for 64-bit simulator which was not agreeing with my CocoaPods


Check to make sure that you don't have a specific framework search path specified. if you go to the info on the target and just remove the framework search path entries it should use the defaults for your specified deployment version.


If you used XCode to create a custom NSManagedObject class and then add to it and generate a new file for the custom class, sometimes XCode will not overwrite your old class and you will be stuck with two of the same files but in different directories. Find the old file and delete it.

The problem could be something else though.


Follow these steps to fix this problem:

Go to project settings and Build Tab. Search for "Other Linker Flags"

Double click on the linker flags for Release and Change:

 ${TARGET_BUILD_DIR}/libCordova.a to ${BUILT_PRODUCTS_DIR}/libCordova.a

Do the same for Debug Clean and build archive again.


In my case

I just removed armv7s and armv64 and build its works.


I had the same Problem, As I was dragging some files .h and .m into my Project and Xcode started showing me this error clang: error: linker command failed with exit code 1 (use -v to see invocation) while running.

Later I discovered that I already have that .h & .m in my Xcode Project under some other SubFolder. So I deleted that Extra .h and .m , Cleaned my Project and Its working now.

clang: error: linker command failed with exit code 1 (use -v to see invocation) This error comes for a number of reason, Thats why this Question has so many Answers. You just need to see & check; what case you fall in.


Try to clean your project, and Compile.


for me the problem was I had loaded same functions twice. Remove -ObjC from Build Settings > Linking > Other Linker Flags.


In my own case, I had duplicate declarations of some keys. I declared some NSString Constants using the extern keyword and did exactly the same thing in two different class files. When I removed one of them, the error disappeared.

extern NSString *const CFDataStatusKey;
extern NSString *const CFDataErrorKey;
extern NSString *const CFDataReasonKey;
extern NSString *const CFDataChannelsKey;

These where declared and initialized respectively in .h and .m files of the two classes. Removing a duplicate solved the issue. Hopes this helps


I solved this problem too weird !

Go to Target > Build Phases > Link Binary with libraries :

Remove all your frameworks and add them again !

Hope it works for you !


This error can also be occurred if you have imported two different versions of same library ,in this case just remove the older version and keep only one version and Magic will work for you.


I had the same problem, and I solved it. In my case, "architectures" setting caused the problem. In my project file, Build Settings tab, Architectures were set to armv6. I changed it to Standard(armv7), do clean and build. Then it worked!


i think the best response is to look into files imports , some imports has a problem .

example : include #import "file.m" or include external file.h

...


With CocoaPod, first install and then open the workspace instead of project as specified on CocoaPod website.

$ pod install

$ open YOUR_PROJECT_NAME.xcworkspace

Just ran into the same issue.

The solution (for me) = check your frameworks.

In my case I had added classes related to CoreData without "CoreData.framework". Adding it solved the MACH_O complaining.


Bizarre error. For me, I just cleaned and restarted Xcode and the problem went away.


This did a trick for me:

Go to

1) Products > clean

2) Windows > Projects

3) Select your project and click on "Delete" derived Data

4) Products > Build


To add onto the list of weird stuff that fixed this issue...

I had some const CGFloat variables in a global header file like so

const NSInteger  globalInteger1 = 2;
const NSInteger  globalInteger2 = 3;

The moment I removed these, all was fine :)


I struggled with this for a little while, and in my case it ended up being the Build Setting under Search Paths called FRAMEWORK_SEARCH_PATHS. It helped that I selected the "Levels" button, which seemed to compare my project, target and "Resolved" settings. I saw that my target setting somehow overrode the default of "$(inherited)", and the overridden value was what XCode "resolved" the setting to be. When I removed the override, which in this case specified the 3.2 sdk, the linker errors went away -- as did some recently appeared warnings about any classes where I called post-4.0 methods.

About those warnings -- I never saw them before I added the MessageUI framework for a recent change. I suspect, but don't know for sure, that when I added that framework, XCode tried to do something clever by adding that override to my target. I didn't do it explicitly at any point. The warnings were,for example, about the URLByAppendingPathComponent method of NSURL, which did not appear until sdk 4.0. Prior to adding the MessageUI framework, I never got that warning. And since I removed the override, I no longer get them.


Fix: Build Settings > Enable Bitcode > No enter image description here


My problem was that in multiple class.m files I had created an NSString named TAG, and I had set the value of TAG to the String name of each class (Ex: NSString * TAG = HWGuiControl). I had done so that then it was easy to prepend my NSLog statements with the name of the class. (I have used this system in Android with great success, great for analyzing program flow 2 years later). Deploying to a device, this all works great. But when its time to create an Archive for distribution, apparently the linker cannot contend with the NSString named TAG appearing in multiple files. Modifying the name(s) of TAG to HWGTAG, etc, did the trick.


Re: Problem as outlined in title:

Just in case anyone else missed the obvious...

I came across this error after installing a new version of Xcode4 and dragging existing files into a new project. I had failed to spot that the 'add to targets' checkbox was left unchecked in the 'Choose options for adding files:' dialog. Correcting my omission in Targets>Build Phases>Compile Sources solved the problem.


In my case i has include .m file thats why compiler shows this type of error.

you should check the latest file import that is not .m file " Sometime i"


If you're getting a Mach-O Linker warning or error that says "Directory not found for option", lookup the path of that directory. If it's missing try downloading the latest version of RestKit and putting the folder in manually.


My issue was because I didn't defined variables as extern in one of my header files and it was redeclared in the .c file.


I had the same and managed to solve it.

In xcode preferences, location tab change value under build location to "Place build products in locations specified by targets".


For Swift language ...

I am getting this error " ld: file too small (length=0) .... "

In my case I just clean the project and then rebuild it ..

Steps:-

1) goto Project -> Clean

2) goto Project -> Build

Hope this helps..


I mistakenly defined a new constant with the same name as an existing constant in a different file and it caused this error for me using xCode 4.3.1. xCode didn't complain but the compiler doesn't like it.


In my case, the cause of such Apple Mach-O Linker error was source code file (.m) inclusion to resource bundle target.

Verify that recently created .m file is not included in a bundle: select the file in project navigator, open file inspector and make sure that resource bundle checkbox is deselected in Target Membership section.


If you are using CoreData, and you use XCode to generate NSManagedObject subclasses for your entities, make sure you only generate one for each entity.

My problem was that it generated multiple NSManagedObject subclasses for the same entity (and put them in different folders).

I just deleted all of them and regenerated the NSManagedObject subclasses.


open .xcworkspace file not .xcodeproj. I repeat open .xcworkspace file. All of your errors will go away.


I had this issue and importing QuartzCore fixed it.


I simply had to files with a main() method and Xcode wasn't happy about that.


I had the same issue: just accidentally deleted a .m file, while .h was in the project. The problem disappeared when I've restored the .m file.


Could you try Unity-Build Settings-Player Settings-SDK Version: Device SDK instead of simulator sdk

Ive had such error and that fixed it


I got this problem after importing a framework. Under 'Build Phases', the framework's name was highlighted in red. I added the framework again and the problem was solved.


Menu > Product > Clean, this is what made it work. I'm not sure about everyone else. I added pic to show.

enter image description here


I just try to create a category class file and got this weird issue..and finally....

Wrong way to create category class that causes the issue:

New File -> Cocoa Touch -> Objective-C class, then I modified the name of files to Category Class like name.. (i.e. OriginalClass_CategoryName.h/m to OriginalClass+CategoryName.h/m, and also modified the contents in the file).

Right way here:

New File -> Cocoa Touch -> Objective-C category, and it'll auto generate files (OriginalClass+CategoryName.h/m).

Oh, how stupid I am!!


I'm running xcode 5. In my case I've to change my "Deployment Target". It was previously set as 3.0 and I change it to 7.0. Now the error message gone. To change your "Deployment Target", follow the steps:

  • Go to your "Project name" (top left)
  • Go to your "Targets" (middle of the screen)
  • Go to "General"
  • "Deployment Info"
  • "Deployment Target"

Change it to current iOS version. -Thanks.


I would like to share one more reason when I got this error:

I had changed the project name in Project Navigator(in Xcode 6.1.1) by single click on it and my project would not compile. I changed the project name back to old name, project was building. Very very strange but yes I have faced this. I hope this information helps.


Examples related to objective-c

Adding a UISegmentedControl to UITableView Keep placeholder text in UITextField on input in IOS Accessing AppDelegate from framework? Warp \ bend effect on a UIView? Use NSInteger as array index Detect if the device is iPhone X Linker Command failed with exit code 1 (use -v to see invocation), Xcode 8, Swift 3 ITSAppUsesNonExemptEncryption export compliance while internal testing? How to enable back/left swipe gesture in UINavigationController after setting leftBarButtonItem? Change status bar text color to light in iOS 9 with Objective-C

Examples related to iphone

Detect if the device is iPhone X Xcode 8 shows error that provisioning profile doesn't include signing certificate Access files in /var/mobile/Containers/Data/Application without jailbreaking iPhone Certificate has either expired or has been revoked Missing Compliance in Status when I add built for internal testing in Test Flight.How to solve? cordova run with ios error .. Error code 65 for command: xcodebuild with args: "Could not find Developer Disk Image" Reason: no suitable image found iPad Multitasking support requires these orientations How to insert new cell into UITableView in Swift

Examples related to xcode

Undefined Symbols error when integrating Apptentive iOS SDK via Cocoapods Xcode 12, building for iOS Simulator, but linking in object file built for iOS, for architecture arm64 iPhone is not available. Please reconnect the device Make a VStack fill the width of the screen in SwiftUI error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65 The iOS Simulator deployment targets is set to 7.0, but the range of supported deployment target version for this platform is 8.0 to 12.1 Xcode 10.2.1 Command PhaseScriptExecution failed with a nonzero exit code Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Xcode 10: A valid provisioning profile for this executable was not found Xcode 10, Command CodeSign failed with a nonzero exit code

Examples related to xcode4

How to select Multiple images from UIImagePickerController Xcode: failed to get the task for process Adding Image to xCode by dragging it from File The identity used to sign the executable is no longer valid Can't ignore UserInterfaceState.xcuserstate Why can I not switch branches? How to Empty Caches and Clean All Targets Xcode 4 and later Apple Mach-O Linker Error when compiling for device How can I build for release/distribution on the Xcode 4? Xcode 4 - "Archive" is greyed out?