Undefined symbols ___llvm_profile_runtime
Asked Answered
B

3

49

As of Xcode 11 using SwiftUI, it looks very difficult/no way to enable code coverage in unit tests and have preview working.

This is what I did:

  1. Select target -> Edit scheme in Xcode
  2. Select Test tab and under Options tab, select Gather coverage for some targets (only select the main target)
  3. Go to a SwiftUI file and preview stops working with following error. Please note you can still use the build option just fine.

And this is the error:

linker command failed with exit code 1 (use -v to see invocation)
    
failedToBuildDylib: ld: warning: directory not found for option '-F/Applications/Xcode.app/Contents/SharedFrameworks-iphonesimulator'
Undefined symbols for architecture x86_64:
  "___llvm_profile_runtime", referenced from:
      ___llvm_profile_runtime_user in Pods_RadioDemo(Pods-RadioDemo-dummy.o)
     (maybe you meant: ___llvm_profile_runtime_user)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

To get away from this issue, I can just turn off code coverage. Obviously that's not what I'm looking for. Please just show me how to get to the perfect world with both preview and code coverage working.

Just a bit of reference is here. Timmmm the good man had some insights on a very similar issue.

Boothman answered 27/9, 2019 at 4:33 Comment(0)
M
103

I was also troubled by the problem. To solve this problem, you may want to add -fprofile-instr-generate to Build Settings > Linking > Other Linker Flags.

This flag is an option used for coverage output. With this setting in my environment, I succeeded in enabling the preview while enabling the coverage.

Misconstruction answered 21/11, 2019 at 11:5 Comment(3)
How did you find this flag?Immediacy
The contents of the error indicate that the coverage runtime library cannot be called. Therefore, we considered adding a flag to enable coverage. In other words, this flag is for linking the coverage runtime library.Misconstruction
How should I use this flag? I tried to add this flag to my main target, and to the target where I'm using the framework, but none worked.Alisha
P
25

I got similar ___llvm_profile_runtime_user errors in an Objective-C project.

It was because one of the frameworks used by my app had been built with Code Coverage turned on. (It was built separately, with "Debug" configuration. It was not built by the current project/workspace.)

I made Xcode happy by turning on the same setting in the app's scheme: Edit Scheme -> Test -> Options -> Code Coverage

Pulverize answered 5/2, 2020 at 17:7 Comment(2)
In my case, this error is gone after enabling code coverage on current target. Thank you! :-)Geoffreygeoffry
d= (◕‿↼ ) I simply removed -fprofile-instr-generate flag from my static-library, but I tested (before that), and this worked, too.Meitner
R
0

podspec file how to add -fprofile-instr-generate to Build Settings > Linking > Other Linker Flags.

Rickert answered 9/11, 2023 at 8:57 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Weatherford

© 2022 - 2024 — McMap. All rights reserved.