Has something changed with how linking works in XCode 10 / Swift 4.2 / SPM?


(Spencer Kohan) #1

I've just download XCode 10 beta 6, and when I try to build a project generated by swift package generate-xcodeproj it suddenly has a ton of build errors.

The structure of the project is:

  • A C++ system module (referenced as a package dependancy)

  • A C-wrapper for the system module (a C-language target within the package)

  • A swift executable target

So my Project.swift looks something like this:

let package = Package(
   ....
  dependencies: [
    .package(url: "../path/to/Clib", .branch("master"))
  ],
  targets: [
   .target(name: "CWrapper", dependencies: []),
   .target(name: "MyExecutable", dependencies: ["CWrapper"])
  ]
)

Now within my swift code, I am frequently using symbols from Clib directly (e.g. constant values):

 import CWrapper

func myFunction() {
  // setLogLevel is defined within CWrapper, where CL_LOG_LEVEL_ERROR is defined within Clib
  CWrapper.setLogLevel(CL_LOG_LEVEL_ERROR)
}

And previously, it was working perfectly while only importing CWrapper in my swift code. However, now if I try to build this, I get the error: Use of unresolved identifier CL_LOG_LEVEL_ERROR

So it seems that something has changed here with how symbols are exported between modules. Is this an intentional change in the new tools version? Are the rules documented somewhere?