Xcode linker error: file too small for architecture x86_64

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?


Solution 1:

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:

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:

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:

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

Solution 5:

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