Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rjstelling/be644d7d3061ac6e53894f2953385f3c to your computer and use it in GitHub Desktop.
Save rjstelling/be644d7d3061ac6e53894f2953385f3c to your computer and use it in GitHub Desktop.

Fixing Linker Errors in Xcode (___llvm_profile_runtime Missing Symbol)

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:

Step 1: Understanding the Issue

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.

Step 2: Confirming the Problem

If you're uncertain whether this is your issue, follow these quick steps:

  • Open Terminal.
  • Run the following command, replacing ProjectA and ProjectB 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!

Step 3: Resolving the Issue

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.

Step 4: Rebuilding the Project

After deleting the auto-generated test plan:

  • Perform a clean build:
    • Menu: Product > Clean Build Folder (or Shift + Command + K)
  • Build your project again:
    • Press Command + B or use Product > Build.

Your linker error should now be resolved!

Troubleshooting Further

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment