Xcode linker error: file too small for architecture x86_64

Objective CIosXcodeMacosCocoa

Objective C Problem Overview


I'm developing an application in Xcode.

When I try to build, this error comes up:

ld: in /Users/theodore/Library/Developer/Xcode/DerivedData/Tower-bkpdifuqssebjdgurzmtirbxejnn/Build/Intermediates/Tower.build/Debug/Tower.build/Objects-normal/x86_64/TWRAppDelegate.o, file too small for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Does anyone know what's wrong?

Objective C Solutions


Solution 1 - Objective C

Stealing @martin-baulig's answer:

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

Solution 2 - Objective C

I usually add a space (could be any character for that matter) to the file in question, remove it and then save. Easier and quicker than a clean build.

Solution 3 - Objective C

To automatically fix this issue Build Script Phase can be added. Goto Xcode -> Your Project -> Your Target -> Build Phases -> + -> New Run Script Phase

Rename it to Xcode Link Fix and move it above Compile Sources phase. Paste this into script body:

# Legacy build system
legacy_dir=`dirname "${LD_DEPENDENCY_INFO_FILE}"`
if [ -d "${legacy_dir}" ]; then
    find "${legacy_dir}" -size 0 | while read -d $'\n' file; do
        rm "$file"
    done
fi

# New build system
if [ -d "${OBJECT_FILE_DIR_normal}" ]; then
    find "${OBJECT_FILE_DIR_normal}" -size 0 | while read -d $'\n' file; do
        rm "$file"
    done
fi

This script checks for object files with zero size and removes them so when compilation is done in next step it success.

You need to add this script for every app target if you have many.

This script takes ~0.1 second to run and saves you from full project rebuild.

Solution 4 - Objective C

rm -rf /Users/hostname/Library/Developer/Xcode/DerivedData

Solution 5 - Objective C

just remove this file by run cmd in your terminal app:

rm /Users/theodore/Library/Developer/Xcode/DerivedData/Tower-bkpdifuqssebjdgurzmtirbxejnn/Build/Intermediates/Tower.build/Debug/Tower.build/Objects-normal/x86_64/TWRAppDelegate.o

Solution 6 - Objective C

Quick way to fix error without complete cache clean:

  1. Open file described in error (in case of this question TWRAppDelegate)
  2. cmd + A
  3. cmd + X
  4. Rebuild - fail
  5. cmd + V
  6. Rebuild - succeed

Solution 7 - Objective C

Since building a clean project may take way too long there is shorter way for those that have the access to the file that is corrupt in the cache:

  • Delete the file (Remove reference)
  • Build project
  • Reinsert file
  • Build project

Full version so you have no trouble finding the file:

  • Find the file in Xcode project navigator
  • Right click the file and press "show in finder" (opens a finder at the location where the file is)
  • Select the file in Xcode and press backspace then click "Remove reference"
  • Build project (it will fail but wait for it to finish)
  • Reinsert file by dragging it from the finder into the same location you just deleted it
  • Build project (should work now)

Solution 8 - Objective C

You can just delete the TWRAppDelegate.o file and continue your build. Copy the full path mentioned in the error message and paste it behind an 'rm' command in your terminal. There's no need to clean/rebuild, delete derived data, add/remove the file from the project, etc.

Solution 9 - Objective C

Step 1. Go to: Project > Build Settings > Search Paths

Step 2. Set "Always Search User Paths" to Yes

Step 3. Build the project (You'll get a warning but the project will build.)

Step 4. Set "Always Search User Paths" back to No and build again to eliminate the warning

Solution 10 - Objective C

A clean rebuild didn´t in my case so i explain how i solved the problem:
- Removed reference to the file (don´t delete the file)
- Add the file to the project again and run

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontbodtView Question on Stackoverflow
Solution 1 - Objective CPeter K.View Answer on Stackoverflow
Solution 2 - Objective CgrassyburritoView Answer on Stackoverflow
Solution 3 - Objective CAnton PlebanovichView Answer on Stackoverflow
Solution 4 - Objective CyeyimilkView Answer on Stackoverflow
Solution 5 - Objective ChaithngnView Answer on Stackoverflow
Solution 6 - Objective CVadim AhmerovView Answer on Stackoverflow
Solution 7 - Objective CMatic OblakView Answer on Stackoverflow
Solution 8 - Objective CJason PepasView Answer on Stackoverflow
Solution 9 - Objective CtlandView Answer on Stackoverflow
Solution 10 - Objective CDavid SantiagoView Answer on Stackoverflow