# "No such module" when using SwiftPM binaryTarget/XCFramework on dependency

**URL:** <https://forums.swift.org/t/no-such-module-when-using-swiftpm-binarytarget-xcframework-on-dependency/48070>\
**Category:** Using Swift\
**Tags:** packagemanager, binary-framework\
**Created:** [May 10, 2021, 10:08pm UTC](https://forums.swift.org/t/no-such-module-when-using-swiftpm-binarytarget-xcframework-on-dependency/48070 "2021-05-10T22:08:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![EfficientSetting](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/efficientsetting/32/13490_2.png) [@EfficientSetting](https://forums.swift.org/u/EfficientSetting)\
**Post date:** [May 10, 2021, 10:08pm UTC](https://forums.swift.org/t/no-such-module-when-using-swiftpm-binarytarget-xcframework-on-dependency/48070/1 "2021-05-10T22:08:50Z")

</div>

My setup is as follows:

- iOS App (Executable) implements Library A via SPM
  - Library A implements StaticLibrary B through .binaryTarget option
  - Library A imports StaticLibraryB in several swift files and compiles fine on it's own

The problem starts when I try to archive the iOS App as I always end up getting the error `no such module 'StaticLibraryB'` on the first of my swift files that import my StaticLibraryB in Library A.

The binaryTarget itself is a zipped xcframework and works fine when manually added to Xcode (not via Package.swift), so I don't think that is killing the compilation.

Looking at other posts, I've already tried putting the binaryTarget into it's own `product` via a new Package.swift file and then dropping the binaryTarget dependency to no avail. Importing StaticLibraryB with `@_implementationOnly` didn't fix it for me either.

Looking at my build log though, it seems that when Xcode invokes swift and SPM to compile LibraryA, it's not processing the xcframework correctly. I've seen this race condition happening before on it's own, where on a cached build SPM correctly uses the `builtin-process-xcframework` option to process XCFrameworks but not on clean builds. Unfortunately, I can't replicate this race condition here no matter how often I try to archive.

I'd appreciate any insights on how we could solve this issue to get past this point for compilation.

---

<div class="post-metadata">

**Author:** ![carsten-wenderdel](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/carsten-wenderdel/32/19843_2.png) [@carsten-wenderdel](https://forums.swift.org/u/carsten-wenderdel)\
**Post date:** [September 30, 2021, 3:40pm UTC](https://forums.swift.org/t/no-such-module-when-using-swiftpm-binarytarget-xcframework-on-dependency/48070/2 "2021-09-30T15:40:40Z")

</div>

My team is experiencing exactly the same problem with the same setup. Happens with Xcode 13 too. It's also listed under "Known issues" in the release notes, so there is hope: [Apple Developer Documentation](https://developer.apple.com/documentation/xcode-release-notes/xcode-13-release-notes)

---

<div class="post-metadata">

**Author:** ![alessionossa](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/alessionossa/32/13462_2.png) [@alessionossa](https://forums.swift.org/u/alessionossa)\
**Post date:** [January 7, 2022, 5:26pm UTC](https://forums.swift.org/t/no-such-module-when-using-swiftpm-binarytarget-xcframework-on-dependency/48070/3 "2022-01-07T17:26:51Z")

</div>

Is there any workaround for this issue?

---

<div class="post-metadata">

**Author:** ![kvarma](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kvarma/32/15126_2.png) [@kvarma](https://forums.swift.org/u/kvarma)\
**Post date:** [July 6, 2022, 4:14pm UTC](https://forums.swift.org/t/no-such-module-when-using-swiftpm-binarytarget-xcframework-on-dependency/48070/4 "2022-07-06T16:14:43Z")

</div>

I had a similar issue in one of our packages when using binary frameworks, where we had to create C target wrapper with .c and .h files, so now this C target wrapper depends on the binary target, here is an example how it needs to be structured in the package

 ![image](https://global.discourse-cdn.com/swift/original/3X/e/8/e8b0070168795d429f795b8455c4ff48dfaa05db.png)

Here is how the package manifest should look

```swift
import PackageDescription

let package = Package(
    name: "TestPackage",
    platforms: [
        .iOS(.v15),
        .macOS(.v12)
    ],
    products: [
        .library(
            name: "TestPackage",
            targets: ["TestPackage"])
    ],
    dependencies: [],
    targets: [
        .target(
            name: "TestPackage",
            dependencies: [
                "TestWrapper"
            ]
        ),
        .target(
            name: "TestWrapper",
            dependencies: ["Test"],
            path: "TestWrapper/TestWrapper"
        ),
        .binaryTarget(
            name: "Test",
            path: "Frameworks/Test.xcframework"
        )
    ],
    swiftLanguageVersions: [.v5]
)

```

Then add your binary framework header import to .h file in the C target wrapper

```swift
#ifndef Bridge_h
#define Bridge_h

#ifdef __OBJC__

// Add all required headers from the binary framework.
#include "Test.h"

#endif

#include <stdio.h>

#endif 

```

Then in your package just import the C target which will provide access to the binary package inside your package

```swift
import TestWrapper

```

---

<div class="post-metadata">

**Author:** ![Jacob2](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@Jacob2](https://forums.swift.org/u/Jacob2)\
**Post date:** [September 22, 2022, 6:53pm UTC](https://forums.swift.org/t/no-such-module-when-using-swiftpm-binarytarget-xcframework-on-dependency/48070/5 "2022-09-22T18:53:02Z")

</div>

works well and really good work around.

---

<div class="post-metadata">

**Author:** ![CassiusPacheco](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cassiuspacheco/32/23565_2.png) [@CassiusPacheco](https://forums.swift.org/u/CassiusPacheco)\
**Post date:** [October 17, 2022, 11:37pm UTC](https://forums.swift.org/t/no-such-module-when-using-swiftpm-binarytarget-xcframework-on-dependency/48070/6 "2022-10-17T23:37:20Z")

</div>

Hi @kvarma, thanks for the example!

I've tried to replicate that in a sample project that the binary has a SPM dependency, to see if it fixes my issue (which is different)

In the .h in the C target wrapper I just imported the whole package #import \<MyBinaryFramework/MyBinaryFramework-Swift.h\>.

Still, no luck. " **Library not loaded: @rpath/Valet.framework/Valet**" which is my binary framework's dependency.

If you do have a second to have a look at the sample project, it's here [GitHub - CassiusPacheco/MyBinaryFrameworkUsageSample at c-wrapper](https://github.com/CassiusPacheco/MyBinaryFrameworkUsageSample/tree/c-wrapper) (c-wrapper branch).

There's a Sample folder with the Sample project that points to that specific commit that implements this details.

Thanks again
