25

After upgrading xcode to 8.0, my application project build with error for device target but building successfully for simulator.

Error is like:
ld: library not found for -lcrt1.3.1.o

What does the solution for this error.

Sandip Patel - SM
  • 3,346
  • 29
  • 27
  • the linker can't find the library it's looking for. It might be similar to http://stackoverflow.com/questions/1471968/xcode-linker-error-library-not-found-for-ladmobdevice – Nathan McCoy Sep 22 '16 at 06:55

4 Answers4

54

After spending lots time, i finally got the reason for this error.

Error: ld: library not found for -lcrt1.3.1.o

Solution: If your project source have deployment target from iOS 5.0 then change it to iOS 6.0 or later and your error will be fix. Now that work fine for device too.

Hurray!!!

Sandip Patel - SM
  • 3,346
  • 29
  • 27
  • 2
    This helped me out with a very old app I was trying to get running again. Thanks! – robertfiorentino Oct 16 '16 at 01:52
  • This did **not** fix the same problem for me. Anybody knows of a different solution? – fishinear Oct 18 '16 at 17:17
  • Sorry, it's fixed now. I had to change the deployment target in both the project and the target settings. – fishinear Oct 18 '16 at 17:32
  • 1
    You saved my day, Thanks! :) – aareeph Oct 24 '16 at 05:44
  • Considering my app was still running on a first gen iPad it was a little bittersweet to make this change. But it did fix the issue. – Vagari Oct 26 '16 at 14:59
  • OH COOOOOME ON !!! You're right, this fixed it for me, but seriously, it's almost 2017, when is Xcode going to grow up, and make itself slightly developer friendly ? This is worse than Microsoft's environment from 20 years ago... it's shockingly awful. – Mike Gledhill Dec 01 '16 at 13:48
  • I got rid of the error after accepting recommended settings (by Xcode) for my project. – mikiqex Jan 02 '17 at 14:54
  • For a standalone Makefile it is necessary to add flag -miphoneos-version-min=6.0 to the linker command. – Marek B. Jan 03 '19 at 10:08
18

crt1.3.1.o is a library that was included in older iOSes (and thus, their SDKs) but is no longer present in newer SDKs.  However, when the project's Deployment Target is set to an older iOS (<6.0, as @Sandy has found), Xcode still tries linking against it.

To keep supporting iOS 5.x in newer Xcodes, one only needs to copy crt1.3.1.o from an older Xcode to the appropriate …/usr/lib/ dir in the newer Xcode.  Xcode will only use crt1.3.1.o if the Deployment Target is <6.0— for projects with a Deployment Target ≥6.0 crt1.3.1.o remains unused and the resulting linked binary is identical to what it was pre-…/usr/lib/crt1.3.1.o-addition.

To get a newer Xcode to properly link a project with a iOS 5.x Deployment Target:

  1. Download an older Xcode that still has crt1.3.1.o from https://developer.apple.com/downloads/.

    I used Xcode 5.1.1, though any Xcode that has iOS 5.x support should work (which, according to Wikipedia should be Xcode 4.2-6.4).

  2. Open the Xcode .dmg and on the disk image, locate the file at /Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS….sdk/usr/lib/crt1.3.1.o.

    Since I used Xcode 5.1.1, mine was at …/iPhoneOS7.1.sdk/usr/lib/crt1.3.1.o.

  3. Copy to the same Xcode.app-relative directory in your newer Xcode: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/crt1.3.1.o.

    My newer-Xcode at time of writing is the latest release, Xcode 8.1 (which out-of-the-box includes the iOS 10.1 SDK and downloadable iOS Simulator support back to iOS 8.1).


Note that you'll need to re-perform these steps after each Xcode upgrade, since the standard Xcode update process is to just blow away Xcode.app and everything contained within with the updated Xcode.app.

Also note that I've successfully tested this using Xcode 8.1 to produce an app with a Deployment Target of iOS 5.0 that'll run on both my iOS 10.1.1 iPad Air 2 & my iOS 6.1.3 iPhone 4S.  I have not, however, submitted a build using this process to the iOS App Store.  While it's unlikely that Apple's certification would have a problem with this (since it is after all their own iOS crt1.3.1.o library; and since there is no other way to build an app against the latest SDK while still supporting iOS back to 5.x, which is almost certainly something that some enterprise clients are still doing), I can't make a firm promise here.

Slipp D. Thompson
  • 33,165
  • 3
  • 43
  • 43
  • Awesome! I had both `Xcode` and `Xcode_7_3`, and performed this: `sudo cp /Applications/Xcode_7_3.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/crt1.3.1.o /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/`, and it solved the problem!! – ishahak Jun 16 '17 at 15:17
0

remove the -lPods-(someCocoaPod) lines in the 'Other Linker Flags' list BUT only if $(inherited) is at the top. At first I was unsure, but the reassuring sign was that I still saw references to my cocoapods when I left the edit mode(inherited). I tested in debug and release, both of which were giving me errors, and the problem was immediately resolved

Deepak Saki
  • 945
  • 1
  • 8
  • 16
0

Instead of using the libraries from an older Xcode install, you can also just recompile them from sources: https://github.com/mringwal/csu-ios

mringwal
  • 476
  • 3
  • 10