CodeVomit
CodeVomit

Reputation: 749

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

Upvotes: 242

Views: 623208

Answers (30)

Daniel
Daniel

Reputation: 975

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

Upvotes: 194

Chintan Shah
Chintan Shah

Reputation: 1764

For our Flutter project, we recently changed the bundle identifier and it doesn't get updated properly in Info.plist. Thus, creating this issue.

We had to add/update following keys in Info.plist with given values:

  • BUNDLE_ID
  • CFBundleDisplayName
  • CFBundleName
  • <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    
  • <key>CFBundlePackageType</key>
    <string>APPL</string>
    
  • <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleExecutable</key>
    <string>${EXECUTABLE_NAME}</string>
    
  • <key>CFBundleShortVersionString</key>
    <string>$(MARKETING_VERSION)</string>
    <key>CFBundleVersion</key>
    <string>$(CURRENT_PROJECT_VERSION)</string>
    

Also, please make sure that your project.pbxproj file also contain the following with static values:

MARKETING_VERSION = 1.0;
CURRENT_PROJECT_VERSION = 1;

If any of these info is not correctly linked then it will keep showing this error.

Upvotes: 0

Andy Rubin
Andy Rubin

Reputation: 25

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

Upvotes: 0

Hassan Rahman
Hassan Rahman

Reputation: 5203

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

$ pod install

$ open YOUR_PROJECT_NAME.xcworkspace

Upvotes: -1

Ahmed Samir
Ahmed Samir

Reputation: 289

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 .

Upvotes: 1

Abhijit Kotangale
Abhijit Kotangale

Reputation: 37

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"

Upvotes: 0

Johannes
Johannes

Reputation: 1440

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

pod deintegrate

pod install

Problem solved!

Upvotes: 23

Dan
Dan

Reputation: 1942

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.

Upvotes: 1

Omkar Jadhav
Omkar Jadhav

Reputation: 504

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.

Upvotes: 3

jer_francis
jer_francis

Reputation: 153

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.

Upvotes: 0

pjuzeliunas
pjuzeliunas

Reputation: 1656

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.

Upvotes: 0

Agu Dondo
Agu Dondo

Reputation: 13579

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

Upvotes: 3

mahi
mahi

Reputation: 532

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

Upvotes: 62

user5284310
user5284310

Reputation:

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

Upvotes: 0

Sebasti&#225;n Lara
Sebasti&#225;n Lara

Reputation: 5541

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

Upvotes: 26

user4886069
user4886069

Reputation:

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

Upvotes: 4

Hardik Mamtora
Hardik Mamtora

Reputation: 1652

In my case

I just removed armv7s and armv64 and build its works.

Upvotes: -2

dasboos
dasboos

Reputation: 1

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.

Upvotes: 0

Daniel
Daniel

Reputation: 3868

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

Upvotes: 0

Curlip
Curlip

Reputation: 395

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

Upvotes: 0

Adela Toderici
Adela Toderici

Reputation: 1112

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

Upvotes: 5

Aviram Netanel
Aviram Netanel

Reputation: 13625

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.

Upvotes: 3

dnaatwork.com
dnaatwork.com

Reputation: 372

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

Upvotes: 34

Niks
Niks

Reputation: 87

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

Upvotes: 4

skypirate
skypirate

Reputation: 673

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.

Upvotes: 0

Gajendrasinh Chauhan
Gajendrasinh Chauhan

Reputation: 3397

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

Upvotes: 214

Jacksonkr
Jacksonkr

Reputation: 32207

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

Upvotes: 0

user2165491
user2165491

Reputation: 101

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

...

Upvotes: 0

Jasmeet
Jasmeet

Reputation: 1531

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.

Upvotes: 0

Rudi
Rudi

Reputation: 4314

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 !

Upvotes: 4

Related Questions