Heinz M.
Heinz M.

Reputation: 694

Can't include C-files in Swift-package with Xcode 11 package manager

I created a Swift 5.1 app with Xcode 11.0 which contains c-files and h-files. A bridging header was automatically generated by Xcode. I entered the necessary #imports. The project compiles and runs as expected. Now I wanted to create a Swift-package which contains the c-files and header-files, the bridging-header file and a Swift file which is a wrapper of the c-functions. I did it in the following way.

  1. I opened file->new->Swift Package
  2. I filled out the name field of the package and the add to: and group: fields
  3. Now the Package.swift appeared in the project.
  4. I moved the Swift files, from the project folder into the Package.swift/Sources/packageName folder.
  5. Just for test reasons I changed to the target/General window and pressed the + Button of Frameworks, Library and embedded Content.
  6. In the appearing List of frameworks I could find the name of my package, as expected.
  7. I canceled the window and went back to move a single c-file into the package folder.
  8. Then I went back to the target/General window and pressed the + Button again and now surprisingly the list doesn't contain my package name

It seems to me, that including c-files into a Swift-package requires some additional steps. I searched in the documentation, but I couldn't find a hint.

Upvotes: 3

Views: 901

Answers (1)

Joe Susnick
Joe Susnick

Reputation: 6772

Basically you cannot at this time have mixed C and Swift sources in the same package.

You can, however, have one target that includes all of your C-files, then have a different target that includes your Swift files but depends on your C-file target.

From your question it seems like you are missing a lot of intermediate steps. If I were you I would try to get a simple example working with just the C-files and then move on to adding the Swift target that depends on that.

Upvotes: 2

Related Questions