# Create XCFramework and reusing it - simple example "error: no such module" when importing

**URL:** <https://forums.swift.org/t/create-xcframework-and-reusing-it-simple-example-error-no-such-module-when-importing/69466>\
**Category:** Using Swift\
**Tags:** spm, swift, packagemanager, xcodebuild, xcframework\
**Created:** [January 16, 2024, 8:34am UTC](https://forums.swift.org/t/create-xcframework-and-reusing-it-simple-example-error-no-such-module-when-importing/69466 "2024-01-16T08:34:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![oliviermartin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/oliviermartin/32/32485_2.png) [@oliviermartin](https://forums.swift.org/u/oliviermartin)\
**Post date:** [January 16, 2024, 8:34am UTC](https://forums.swift.org/t/create-xcframework-and-reusing-it-simple-example-error-no-such-module-when-importing/69466/1 "2024-01-16T08:34:38Z")

</div>

Context: I am trying to create a XCFramework that I can reuse it in my Swift app. My example is based on SPM (Swift Package Manager) but I had the same import error `no such module` when I tried to import my XCFramework in XCode.

Here is **the code for XCFramework** :

- `Package.swift`

```swift
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "MySDK",
    platforms: [.macOS(.v14), .iOS(.v13), .watchOS(.v6)],
    products: [
        .library(name: "MySDK", type: .dynamic, targets: ["MySDK"]),
    ],
    targets: [
        .target(name: "MySDK")
    ]
)

```

- `Sources/MySDK/my_sdk.swift`

```swift
public func myHelloStr() -> String {
    return "Bonjour le monde!"
}

```

To generate the XCFramework:

```swift
$ xcodebuild build -scheme MySDK -destination "platform=macOS" -derivedDataPath DerivedData SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
$ xcodebuild -create-xcframework -framework DerivedData/Build/Products/Debug/PackageFrameworks/MySDK.framework -output MyFramework.xcframework

```

I can see `MyFramework.xcframework` folder with

```
- `Info.plist`
- `macos-x86_64/MySDK.framework/MySDK`
- `macos-x86_64/MySDK.framework/Resources/Info.plist`
- `macos-x86_64/MySDK.framework/Versions/A/MySDK`
- `macos-x86_64/MySDK.framework/Versions/A/Resources/Info.plist`
- `macos-x86_64/MySDK.framework/Versions/Current/MySDK`
- `macos-x86_64/MySDK.framework/Versions/Current/Resources/Info.plist`

```

Then I create a new SPM project `MyApp`

- with `Package.swift`

```swift
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "TestApp",
    platforms: [.macOS(.v14), .iOS(.v13), .watchOS(.v6)],
    products: [
        .executable(name: "MyApp", targets: ["MyApp"])
    ],
    targets: [
        .executableTarget(name: "MyApp",
            dependencies: [
                .target(name: "MyFramework")
            ]
        ),
        .binaryTarget(
            name: "MyFramework",
            path: "../test_sdk/MyFramework.xcframework"
        )
    ]
)

```

- And `Sources/MyApp/main.swift`:

```swift
import MySDK

print("Hello World: \(myHelloStr())")

```

```swift
$ swift run
Building for debugging...
error: emit-module command failed with exit code 1 (use -v to see invocation)
/Users/olivier/dev/test_app/Sources/MyApp/main.swift:1:8: error: no such module 'MySDK'
import MySDK
       ^
/Users/olivier/dev/test_app/Sources/MyApp/main.swift:1:8: error: no such module 'MySDK'
import MySDK
       ^
error: fatalError

```

If I generate my XCFramework using `xcodebuild archive` instead of `xcodebuild build` such as described in this doc [https://developer.apple.com/documentation/xcode/creating-a-multi-platform-binary-framework-bundle:](https://developer.apple.com/documentation/xcode/creating-a-multi-platform-binary-framework-bundle:)

```swift
$ xcodebuild archive -scheme MySDK -destination "platform=macOS" -derivedDataPath DerivedData -archivePath "archives/MyFramework" SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
(...)
**ARCHIVE SUCCEEDED**
$ xcodebuild -create-xcframework -archive archives/MyFramework.xcarchive -framework MySDK.framework -output MyFramework.xcframework
error: the path does not point to a valid framework: /Users/olivier/dev/test_sdk/archives/MyFramework.xcarchive/Products/Library/Frameworks/MySDK.framework

```

... it's not normal because I have these paths in `/Users/olivier/dev/test_sdk/archives/MyFramework.xcarchive/Products`:

- `/Users/olivier/dev/test_sdk/archives/MyFramework.xcarchive/Products/Users/olivier/Objects/MySDK.o`
- `/Users/olivier/dev/test_sdk/archives/MyFramework.xcarchive/Products/usr/local/lib/MySDK.framework/...`

I do not know if it is matter but there is no `*.swiftinterface` in my XCFramework. I do not know if it is expected. But after building with `xcodebuild build` or `xcodebuild archive` , these files are present in subdirectories of `DerivedData`.

```swift
$ xcodebuild -version 
Xcode 15.2
Build version 15C500b

```

---

<div class="post-metadata">

**Author:** ![oliviermartin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/oliviermartin/32/32485_2.png) [@oliviermartin](https://forums.swift.org/u/oliviermartin)\
**Post date:** [January 17, 2024, 2:06pm UTC](https://forums.swift.org/t/create-xcframework-and-reusing-it-simple-example-error-no-such-module-when-importing/69466/2 "2024-01-17T14:06:19Z")

</div>

Hmmm, after looking the file/directory tree of an XCFramework I found on Internet, I tried to duplicate it with the generated files (I saw is missing `MySDK.swiftmodule` from the XCFramework)

So copying `MySDK.swiftmodule` to the XCFramework fixes my issue.

```swift
mkdir ./MyFramework.xcframework/macos-x86_64/MySDK.framework/Versions/A/Modules
cp ./DerivedData/Build/Products/Debug/MySDK.swiftmodule ./MyFramework.xcframework/macos-x86_64/MySDK.framework/Versions/A/Modules/
ln -s ./MyFramework.xcframework/macos-x86_64/MySDK.framework/Versions/A/Modules ./MyFramework.xcframework/macos-x86_64/MySDK.framework/Modules

```

Is it a `xcodebuild` bug or a missing step in my XCFramework generation?
