Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined symbols ___llvm_profile_runtime

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.

like image 457
UndergroundFox Avatar asked Sep 27 '19 04:09

UndergroundFox


People also ask

What is an undefined symbol?

A symbol remains undefined when a symbol reference in a relocatable object is never matched to a symbol definition. Similarly, if a shared object is used to create a dynamic executable and leaves an unresolved symbol definition, an undefined symbol error results.

What is undefined symbols for architecture x86_64?

Why Is the Undefined Symbols for Architecture x86_64: Error Happening? This error is happening due to the lack of included values inside the declared statements in your code. The browser is going to render the information incorrectly and show this error, especially if you are working with Main and Similarity tools.

What does undefined symbol mean in Xcode?

Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_xxx", referenced from: objc-class-ref in yyy.o. This generally means, you are calling "xxx" (it may be a framework or class) from the class "yyy". The compiler can not locate the "xxx" so this error occurs.


1 Answers

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.

like image 193
AkkeyLab Avatar answered Sep 20 '22 11:09

AkkeyLab