8

I am currently blocked by a linker error which happens ONLY on XCode5 (XCode4 compiles fine) and ONLY on the simulator (normal devices compile fine).

When I try to compile, I get a "Apple Mach-O Librarian Error" which gives me the following wall of text:

Libtool build/DevOnly-iphonesimulator/libCozi\ Common\ Code.a normal i386 cd /Users/jr/ios/app/iCozi setenv IPHONEOS_DEPLOYMENT_TARGET 4.3 setenv PATH "/Applications/XCode5/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/XCode5/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Applications/XCode5/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static -arch_only i386 -syslibroot /Applications/XCode5/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk -L/Users/jr/ios/app/iCozi/build/DevOnly-iphonesimulator -L/Users/jr/ios/app/iCozi/../../ext/aiMatch/SASIA_iOS_SDK-iphonesimulator -L/Users/jr/ios/app/iCozi/../../ext/GoogleAdsSDK-iphone-v3.1/Library -L/Users/jr/ios/app/iCozi/../../ext/Google\ Analytics\ SDK/Library -L/Users/jr/ios/app/iCozi/../../ext/AdMarvel_iOS_SDK_2_9_1/AdMarvelSDK -L/Users/jr/ios/app/iCozi/../../ext/libComScore-1.1107.12 -L/Users/jr/ios/app/iCozi/../../ext/TestFlightSDK -L/Users/jr/ios/app/iCozi/../../ext/mBlox-SDK/Debug-universal -L/Users/jr/ios/app/iCozi/../../ext/mBlox-SDK/Release-universal -L/Users/jr/ios/app/iCozi/../../ext/FacebookSDK/FacebookSDK.framework/Versions/A -L/Users/jr/ios/app/iCozi/../../ext/GoogleConversionTrackingSDK -L/Users/jr/ios/app/iCozi/../../ext/TapjoyAdvertiserSDK/TapjoyAdvertiserLibrary -L/Users/jr/ios/app/iCozi/../../ext/MobileAppTracker.framework/Versions/A -filelist /Users/jr/ios/app/iCozi/build/iCozi.build/DevOnly-iphonesimulator/Cozi\ Common\ Code.build/Objects-normal/i386/Cozi\ Common\ Code.LinkFileList -all_load -ObjC -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/jr/ios/app/iCozi/build/iCozi.build/DevOnly-iphonesimulator/Cozi\ Common\ Code.build/Cozi\ Common\ Code.xcent -framework MobileAppTracker /Applications/XCode5/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/usr/lib/libz.dylib -framework Foundation -framework UIKit -framework CoreGraphics -framework QuartzCore -framework Security -framework MobileCoreServices -framework CFNetwork -framework SystemConfiguration -weak_framework MessageUI -framework QuartzCore /Users/jr/ios/ext/three20/Build/Products/Release-iphonesimulator/libThree20.a /Users/jr/ios/ext/three20/Build/Products/Release-iphonesimulator/libThree20UI.a /Users/jr/ios/ext/three20/Build/Products/Release-iphonesimulator/libThree20UINavigator.a /Users/jr/ios/ext/three20/Build/Products/Release-iphonesimulator/libThree20UICommon.a /Users/jr/ios/ext/three20/Build/Products/Release-iphonesimulator/libThree20Style.a /Users/jr/ios/ext/three20/Build/Products/Release-iphonesimulator/libThree20Network.a /Users/jr/ios/ext/three20/Build/Products/Release-iphonesimulator/libThree20Core.a -framework CoreLocation -weak_framework MediaPlayer -weak_framework iAd -framework AVFoundation -framework AudioToolbox -lGoogleAnalytics /Applications/XCode5/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/usr/lib/libsqlite3.0.dylib -weak_framework EventKit -weak_framework EventKitUI -lTestFlight -framework comScore -framework MDS-SDK-PhoneGap -lMDSCore -framework FacebookSDK -lGoogleConversionTracking /Users/jr/ios/ext/TapjoyAdvertiserSDK/TapjoyAdvertiserLibrary/TapjoyAdvertiserLibrary.a /Users/jr/ios/ext/FacebookSDK/FacebookSDK.framework/Versions/A/FacebookSDK /Users/jr/ios/ext/MobileAppTracker.framework/Versions/A/MobileAppTracker -o /Users/jr/ios/app/iCozi/build/DevOnly-iphonesimulator/libCozi\ Common\ Code.a

/Applications/XCode5/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: unknown option character `X' in: -Xlinker Usage: /Applications/XCode5/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT] Usage: /Applications/XCode5/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -dynamic [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-o output] [-install_name name] [-compatibility_version #] [-current_version #] [-seg1addr 0x#] [-segs_read_only_addr 0x#] [-segs_read_write_addr 0x#] [-seg_addr_table ] [-seg_addr_table_filename ] [-all_load] [-noall_load] Command /Applications/XCode5/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool failed with exit code 1

The root of the problem seems to be "unknown option character `X' in: -Xlinker", but Google doesn't give much help with that error: https://www.google.com/search?q=%22%60X%27+in%3A+Xlinker%22

"XLinker" appears four times in the mess above (" . . . -all_load -ObjC -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/jr/ios/app/iCozi/build/iCozi.build/DevOnly-iphonesimulator/Cozi\ Common\ Code.build/Cozi\ Common\ Code.xcent . . . ")

Just for grins, I tried removing the spaces from the "Cozi Common Code" target name, but that didn't help.

Again, this compiles just fine on XCode4 simulator, and it compiles just fine in XCode5 for running on physical devices, including an iPod and an iPad, but every simulator in XCode5 has this problem (iPhone/iPod/iPad, both normal and retina, on iOS5/iOS6/iOS7).

I'd REALLY appreciate anybody who can help me get to the bottom of this. Thanks!

dacoinminster
  • 3,637
  • 2
  • 18
  • 23
  • 1
    Did you tried iOS Simulator>Reset Content and Settings? – Nikos M. Oct 30 '13 at 21:10
  • @NikosM. yeah, I just tried that. No luck :( – dacoinminster Oct 30 '13 at 21:12
  • 1
    Did you check your Build Settings for anything unusual (like an X character in Linker Options :-)) – gWiz Oct 30 '13 at 21:40
  • @gWiz I did look through all my linker options, and didn't see anything suspicious – dacoinminster Oct 30 '13 at 21:49
  • 2
    You're compiling a static library (`.a`) while specifying entitlements; which looks to be the issue here. You've probably got an inherited setting that is specifying it for the simulator while not specifying it for the device. It's about as clear as mud. – Anya Shenanigans Oct 30 '13 at 22:12
  • @Petesh The static library is part of a larger project which does use entitlements. I can tell because in the "Summary" tab for the primary target, I see that it is loading an entitlements file. The summary tab for the static library doesn't have any place for choosing an entitlements file, which seems correct since a static library can't have entitlements. I agree: about as clear as mud :( – dacoinminster Oct 30 '13 at 22:27
  • @Petesh I finally fixed this bug by going to project settings -> Code Signing -> Code Signing Entitlements -> DevOnly, and completely deleting the "entitlements-DevOnly.plist" setting that was there. Now our code runs on the simulator just fine. Since your comment led me to the solution, would you mind posting an actual answer so I can award you the bounty? Thanks! – dacoinminster Nov 09 '13 at 00:47
  • See also: [Static Linking with Swift, XCode6-Beta](http://stackoverflow.com/questions/24041962/static-linking-with-swift-xcode6-beta). You may be importing a static library which is trying to use Swift code, which is not supported at this time. – Senseful May 20 '15 at 22:45

9 Answers9

13

In order to understand the error, you have to understand what the command is attempting to do.

In this case it's using Libtool, which is a slightly altered version of libtool. There are some options that are specified in the command line, but what we're looking for is the destination file, and this is passed in as the -o option, who's argument is /Users/jr/ios/app/iCozi/build/DevOnly-iphonesimulator/libCozi\ Common\ Code.a, and the type of library we're generating, and in this case it's -static. Both options together explicitly state that you're making a static library archive.

Because you're making a static library archive, the only thing you're actually doing is taking .o files and possibly .a files and turning them into another .a file. This can be roughly equated to the creating of a .zip file from a set of files (.o), and the contents of other .zip files (.a). There are very few things you can do while making this archive, for example you can't specify libraries that need to be implicitly linked while building a static archive, you can't specify that you're going to require entitlements.

libtool is complaining because it doesn't understand the options that are being used for a static library that are being passed in. In this case the options are:

-Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/jr/ios/app/iCozi/build/iCozi.build/DevOnly-iphonesimulator/Cozi\ Common\ Code.build/Cozi\ Common\ Code.xcent

These are options that are present when you're trying to link in an entitlements file, which means that some options is specifying the use of an entitlements file. In this case, you found the correct solution yourself, which was to remove the entitlements file specified in the project settings -> Code Signing -> Code Signing Entitlements -> DevOnly.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
  • 3
    Sigh. Or instead of attempting to understand the issue, one can sacrifice a chicken and/or delete the derived data/preferences/whatever and hope for the best. I am absolutely amazed at some of the answers given here. – quellish Nov 11 '13 at 09:00
  • 1
    Bounty awarded. Thanks so much! @quellish He unblocked us, so he gets the bounty. If you knew of a better answer, I wish you had posted it! – dacoinminster Nov 11 '13 at 16:18
  • Thanks for the in-depth explanation. – Dan Loewenherz Jun 24 '14 at 17:03
2

I met the same problem, and my approach to solve is to erase the unsupported option "-Xliner" in the command line of libtool (Actually i think this option should be supported by libtool, as is documented in the manual of libtool in gnu. Might be xcode disable it in libtool?)

To erase this option, i first try to find out which setting generate it. In my side, it's code signing. I built the project with code signing "iOS Distribution" while an identity correspond to this signing is also exist in keychain. This will result in the build tool read this identity and try to do something like generate extra link option for libtool.

To dismiss it, I change the signing to "iOS Developer". And i think a remove of correspond identity also works.

Hope my solution could be helpful to you.

jingxw
  • 65
  • 6
2

First check the scheme that you build for Debug (Product -> Scheme -> Manage schemes then select target and press Edit) Go to the Build Settings (both in project and target), find Code signing and change to Automatic in Debug in Provisioning Profile and Don't code sign in Debug in Code Signing Identity. It helped me, hope it will help someone else too)

1

My first quick take on this error is that it's a false alarm. If I were you, I would do some troubleshooting accordingly and clean up Xcode, project and simulator settings etc.

Try deleting Xcode's preferences file (from common and user library both) and restart Xcode -

/Library/Preferences

com.apple.dt.Xcode

/Users/YourUsername/Library/Preferences ( I have following 3 files related to Xcode there )

com.apple.dt.Xcode.plist

com.apple.dt.Xcode.LSSharedFileList.plist

com.apple.dt.Xcode.plist.BoGEJ0T

Alternatively - try building the project on some other machine (or switch to some other user on same machine).

Ashok
  • 6,224
  • 2
  • 37
  • 55
  • Thanks for the ideas! My Co-worker has the exact same error message on his machine, so I don't think xcode settings are the problem. I did try closing xcode and killing all the xcode preference files you describe, but when I opened xcode, cleaned, and recompiled, the problem is still there. – dacoinminster Oct 30 '13 at 21:48
  • 1
    Then I suspect, the `.xcodeproj` file got corrupted. If easily possible, then create fresh/new project and pull in source and resource files there. If not, then 'show package content' on the xcodeproj bundle/file and open the content files in textedit and look out for some 'X' etc. – Ashok Oct 30 '13 at 21:55
  • I think the "X" is may actually referring to "XLinker"? I've been looking through everything in my project file for stray X's all the same with no success. Creating a new project file would be a BIG pain, and anyway, it doesn't seem likely that the project would compile to a normal device if the xcodeproj file was corrupted. – dacoinminster Oct 30 '13 at 22:00
  • 1
    xcodeproj content files are kind of xml files so it may be that the tags relevant to simulator got corrupted. Hence, compiler complains when targeted on simulator. Anyways, wish all the very best, I gotta leave now. – Ashok Oct 30 '13 at 22:04
  • Yeah, I can still load up Xcode4 and compile this for the simulator on that platform, so methinks if the project file has a simulator-specific corruption, it must somehow also be xcode5-specific! Thanks for your ideas . . . – dacoinminster Oct 30 '13 at 22:07
1

This is not the ultimate solution, But in my case, This accord because I was trying to use "ReactiveCocoa" with this pod:

pod 'ReactiveCocoa', '3.0.0-alpha.1'

And it automatically installed "LlamaKit", witch you don't necessarily need when using ReactiveCocoa...

So first I removed the podfile, run "pod install". Then deleted the "Podfile.lock" file (At the same folder as your project).

Then used this pod:

pod 'ReactiveCocoa'

and run "pod install" once again. clean project, run, and good luck.

MCMatan
  • 8,623
  • 6
  • 46
  • 85
1

I had a file with a "+" in the file name in my pods folder for some reason. Deleted it and it worked great

UKDataGeek
  • 6,338
  • 9
  • 46
  • 63
1

I also met the Apple Mach-O Librarian Error. But after checking my build settings, I found Code Signing entitlement of both myProject and Pods were empty.

As it might be a problem of static library, I just changed the Mach-O type setting of Pods-myExtension from static library to Dynamic library and found it worked!

Mach-O type can be found in Pods-myExtension -> Build settings -> Linking.

Hope it helps:)

thundertrick
  • 1,634
  • 1
  • 17
  • 22
1

FWIW, this exact error can also occur on Xcode 7.3.1 if the "Code Signing Entitlements" build setting has been mistakenly set for an static library build target, where it doesn't really apply.

Oscar Hierro
  • 1,117
  • 1
  • 10
  • 15
  • +1 for this. This works for me. I accidentally added the _.entitlements_ file to my Static Library build target causing me the Libtool error. – ᴳᴿᴵᴹᴹ Jan 12 '17 at 10:56
0

To fix this issue , kindly change the schema to debug in simulator, this is because you have selected to release.