Issue with Module Import and Archiving a Mixed Swift/C Library Using Swift Package Manager

Hello everyone,

I’m encountering an issue when trying to build and archive my library BleeckerCodesLib using Swift Package Manager. My project is structured with two targets:

  • CBleeckerLib: A C target that contains my image processing code (C source files and public headers).

  • BleeckerCodesLib: A Swift target that depends on CBleeckerLib and performs an import CBleeckerLib.

Below is the relevant portion of my Package.swift:

// swift-tools-version:5.7
import PackageDescription

let package = Package(
    name: "BleeckerCodesLib",
    platforms: [.iOS(.v16)],
    products: [
        .library(name: "BleeckerCodesLib", targets: ["BleeckerCodesLib"])
    ],
    targets: [
        .target(
            name: "CBleeckerLib",
            publicHeadersPath: "include"
        ),
        .target(
            name: "BleeckerCodesLib",
            dependencies: ["CBleeckerLib"]
        )
    ]
)

Directory Structure

My project directory looks like this:

BleeckerCodesLib/
├── BleeckerCodesLib.xcodeproj/
│   └── xcuserdata/
│       └── robertopitarch.xcuserdatad/
│           └── xcschemes/
│               └── xcschememanagement.plist
├── BleeckerCodesLib.h
├── Package.swift
└── Sources/
    ├── CBleeckerLib/
    │   ├── bleecker-lib.c
    │   └── include/
    │       ├── bleecker-lib.h
    │       └── CBleeckerLib.h
    └── BleeckerCodesLib/
        ├── UIImage+Extensions.swift
        ├── ImageProcessingUtility.swift
        ├── APIManager.swift
        ├── BleeckerCodesLib.swift
        ├── CameraView.swift
        ├── RealTimeCameraView.swift
        └── BleeckerCameraWrapper.swift

Code Example

In my Swift code (for example, in BleeckerCodesLib.swift), I import the C module as follows:

import SwiftUI
import UIKit
import CBleeckerLib  // Import the C module

public struct BleeckerCodes {
    public struct DetectedCode {
        public let code: String
        public let corners: [CGPoint]
        
        public init(code: String, corners: [CGPoint]) {
            self.code = code
            self.corners = corners
        }
    }
    
    // Initialization function
    public static func initializeLibrary() -> String {
        bleecker_init() // Call the C module function
        return "BleeckerCodesLibrary initialized!"
    }
    
    // ... other functions
}

The Problem

When I try to compile or archive the project using commands such as:

xcodebuild archive -project BleeckerCodesLib.xcodeproj -scheme BleeckerCodesLib -destination "generic/platform=iOS" -archivePath "archives/BleeckerCodesLib"

I receive the error: "no such module 'CBleeckerLib'"


Any assistance or step-by-step guidance on resolving this integration issue would be greatly appreciated.

Thank you in advance!

Issue with Module Import and Archiving a Mixed Swift/C Library Using Swift Package Manager
 
 
Q