求助:处理Xcode中"file too small"链接器错误
That tiny 19-byte libc++.dylib file in your project is almost certainly a broken symlink, empty placeholder, or corrupted copy—definitely not the actual system library the linker expects. Let's walk through the most reliable fixes to get your build working again:
Replace the broken file with the system's official libc++.dylib
System libraries likelibc++.dylibshouldn't be stored locally in your project directory. Instead, link against the version provided by macOS/Xcode:- First, delete the broken
/Users/xxx/xxx/xxx/libc++.dylibfile from your project folder (and remove its reference from Xcode if it's still listed). - In Xcode, navigate to your target's Build Phases > Link Binary With Libraries.
- Click the
+button, search forlibc++.dylib(orlibc++.tbdfor newer SDKs), select it, and add it to your list. This ensures you're using the valid, up-to-date library from the system SDK.
- First, delete the broken
Fix incorrect file references in your project
If you previously added a local copy of the library, double-check its path in Xcode:- Select the
libc++.dylibentry in the Project Navigator. - Open the File Inspector (right-hand pane).
- Verify the Path field points to a valid file. If it's a relative path that's broken, update it to the system path (e.g.,
/usr/lib/libc++.dylib) or remove the reference entirely and add it via the Build Phases method above.
- Select the
Wipe derived data and rebuild from scratch
Corrupted derived data can sometimes cause weird linker issues:- Go to Xcode > Settings > Locations.
- Click the arrow next to Derived Data to open the folder.
- Delete the folder corresponding to your project.
- Back in Xcode, clean your project with
Cmd+Shift+K, then rebuild withCmd+B.
Verify your Xcode installation
If the system SDK itself is corrupted, this can lead to missing or broken library references:- Go to Xcode > Settings > Locations and ensure Command Line Tools is set to your active Xcode version.
- If problems persist, try updating Xcode to the latest version via the App Store, or reinstall it completely to fix any corrupted SDK files.
A quick note: Storing local copies of system libraries is generally a bad practice—they can become outdated or corrupted as you update macOS or Xcode, leading to exactly the kind of error you're seeing. Using the system-provided library via Xcode's build settings avoids these issues long-term.
内容的提问来源于stack exchange,提问作者Frostless

