Encountering a linker error in Xcode can be frustrating, especially when dealing with third-party Swift packages. One common error looks like this:
Undefined symbols for architecture arm64:
"___llvm_profile_runtime", referenced from:
___llvm_profile_runtime_user in PocketSVG.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Let's break down a friendly and straightforward solution to fix this issue step-by-step:
This error typically arises when certain code coverage or profiling settings in Xcode are incorrectly enabled, causing linker issues when compiling projects using Swift Packages (like PocketSVG).
In our scenario, this error surfaced because the build setting CLANG_COVERAGE_MAPPING
was enabled (YES
) in the problematic project, but not in a working project. Unfortunately, this setting is tricky to locate directly within Xcode's build settings interface.
If you're uncertain whether this is your issue, follow these quick steps:
- Open Terminal.
- Run the following command, replacing
ProjectA
andProjectB
with your actual scheme names:
xcodebuild -workspace Project.xcworkspace -scheme "ProjectA" -showBuildSettings > ProjectA-BuildSettings.txt
Repeat this for a known good project (ProjectB
), then compare the two text files using your preferred text editor or comparison tool (like BBEdit).
If you see:
CLANG_COVERAGE_MAPPING = YES
in your problematic project's settings, you have found your culprit!
Since CLANG_COVERAGE_MAPPING
isn't easily visible or adjustable in the standard build settings view, here's a quick workaround:
-
Open your Xcode project.
-
Go to the top menu bar and select:
Product > Test Plan > Manage Test Plans
-
In the window that appears, look for an auto-generated test plan (usually named something like "Auto Generated").
-
Select this test plan and delete it.
Deleting this autogenerated test plan removes the hidden coverage settings causing your linker issue.
After deleting the auto-generated test plan:
- Perform a clean build:
- Menu:
Product > Clean Build Folder
(orShift + Command + K
)
- Menu:
- Build your project again:
- Press
Command + B
or useProduct > Build
.
- Press
Your linker error should now be resolved!
If this doesn't immediately fix your issue:
- Double-check that no manual test plans still have code coverage enabled.
- Ensure your project's scheme isn't explicitly setting code coverage.
- Select your scheme > Edit Scheme > Test tab > Options, and ensure "Code Coverage" is unchecked unless needed.
Following these steps should swiftly resolve the ___llvm_profile_runtime
linker error and get your project compiling again smoothly. Happy coding!