35

I'm creating a weather app which gets information from a web site. Everything was fine the last time I was coding (last night), I was able to compile and run the simulator with no errors. Just today when I launch the same project, without changing anything, I got a "Apple Mach-O Linker Error". Could you all help with this please?

Here's the details of the error:

Ld /Users/Allister/Library/Developer/Xcode/DerivedData/Haze_Meter-dkjjcmjehyitmcbhkcbujnsrhwpu/Build/Products/Debug-iphonesimulator/Haze\ Meter.app/Haze\ Meter normal x86_64
    cd "/Users/Allister/Documents/XCODE/Haze Meter"
    export IPHONEOS_DEPLOYMENT_TARGET=8.3
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.3.sdk -L/Users/Allister/Library/Developer/Xcode/DerivedData/Haze_Meter-dkjjcmjehyitmcbhkcbujnsrhwpu/Build/Products/Debug-iphonesimulator -F/Users/Allister/Library/Developer/Xcode/DerivedData/Haze_Meter-dkjjcmjehyitmcbhkcbujnsrhwpu/Build/Products/Debug-iphonesimulator -filelist /Users/Allister/Library/Developer/Xcode/DerivedData/Haze_Meter-dkjjcmjehyitmcbhkcbujnsrhwpu/Build/Intermediates/Haze\ Meter.build/Debug-iphonesimulator/Haze\ Meter.build/Objects-normal/x86_64/Haze\ Meter.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -objc_abi_version -Xlinker 2 -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -Xlinker -add_ast_path -Xlinker /Users/Allister/Library/Developer/Xcode/DerivedData/Haze_Meter-dkjjcmjehyitmcbhkcbujnsrhwpu/Build/Intermediates/Haze\ Meter.build/Debug-iphonesimulator/Haze\ Meter.build/Objects-normal/x86_64/Haze_Meter.swiftmodule -mios-simulator-version-min=8.3 -Xlinker -dependency_info -Xlinker /Users/Allister/Library/Developer/Xcode/DerivedData/Haze_Meter-dkjjcmjehyitmcbhkcbujnsrhwpu/Build/Intermediates/Haze\ Meter.build/Debug-iphonesimulator/Haze\ Meter.build/Objects-normal/x86_64/Haze\ Meter_dependency_info.dat -o /Users/Allister/Library/Developer/Xcode/DerivedData/Haze_Meter-dkjjcmjehyitmcbhkcbujnsrhwpu/Build/Products/Debug-iphonesimulator/Haze\ Meter.app/Haze\ Meter

and at the bottom:

ld: file too small (length=0) file '/Users/Allister/Library/Developer/Xcode/DerivedData/Haze_Meter-dkjjcmjehyitmcbhkcbujnsrhwpu/Build/Intermediates/Haze Meter.build/Debug-iphonesimulator/Haze Meter.build/Objects-normal/x86_64/ViewController.o' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I've checked other "Apple Mach-O Linker Error" on StackOverflow but they seem to be having a different "ld" with mine, albeit the same "clang".

Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165
Allister Bah
  • 1,134
  • 3
  • 13
  • 19

6 Answers6

101

Try a full rebuild / clean. It's possible that the a previous build has been abnormally aborted, leaving the ViewController.o file corrupted or zero-size.

To clean: In Xcode "Product" menu, select "Clean" (shortcut: Cmd+Shift+K)

To rebuild: In Xcode "Product" menu, select "Build" (shortcut: Cmd+B)

If it doesn't work: In Xcode "Product" menu, hold down Option key, and select "Clean Build Folder"

reference from HERE.

Community
  • 1
  • 1
Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165
8

You don't (usually) have to clean, just open the file it mentions and resave it so that xcode thinks it changed. Then you can just do an incremental build (much faster).

colinta
  • 3,536
  • 1
  • 28
  • 18
  • 2
    This saves a lot of work. If it doesn't work, change something in the file and rebuild to make it work. – Tieme Aug 10 '17 at 08:52
1

I had the same problem. It turned out to be that one of my frameworks I added externally could not be found. To fix it I removed the reference to it, re downloaded it, then re added it to my project.

Carter Cobb
  • 790
  • 7
  • 13
0

For me it was because of a empty UINavigationController stranded in storyboard.

Hope this helps the needy ones.

Nikhil Manapure
  • 3,748
  • 2
  • 30
  • 55
0

in my case.i get this error in a framework which is accessed by cocoapods. i fix this error by run cmd 'pod cache clean' and then clean and rebuild project.

0

I had the same issue with AppCode. Invalidate Caches / restart didn't help. Fixed issue by manually deleting Library/Caches/AppCodeXXXX/DerivedData folder.

Jakub Sowa
  • 31
  • 3