Undefined symbols ___llvm_profile_runtime when building a package with code coverage turned on

Hi, I've already reported this bug as https://bugs.swift.org/browse/SR-14788, but I also wanted to post here in the hopes that somebody's stumbled upon the same thing (and had found a workaround).

In a nutshell: I have a Swift package with Objective-C code that depends on another package with Swift code. When building it without code coverage enabled, everything builds fine. When code coverage is turned on, I get undefined symbols. Ideally I'd rewrite this code to Swift, but that's not feasible at the moment.

StackOverflow mentions adding -fprofile-instr-generate to linker flags, but I don't know if that is even possible in a package manifest (or at least without using unsafe flags).

I've run into this issue too. I don't know if it's solvable, and adding that flag for standard builds seem problematic.

What I've found is this issue seems to happen when SwiftPM and possibly Xcode decide to build as a dylib. When my libraries are built as static libraries I don't get this error.

I'll be opening a bug with Apple when I get a chance as I'm not sure if the bug is in SwiftPM or Xcode.

Unfortunately this has to be dynamic as the library is included in multiple other libraries, so I would get duplicate symbols otherwise.

Terms of Service

Privacy Policy

Cookie Policy