Quantcast
Viewing latest article 23
Browse Latest Browse All 166

Swift 6.1 and "redefinition of module"

After upgrading (Xcode) to Swift 6.1, one of my projects failed to compile.
It prompted redefinition of module 'CLib' during compilation.

The simplified project (source code can be found here MacroTest) is like this:

  • CLib
  • MyLib
    • CLib
    • MyMacro
  • MyMacro
    • CLib

In short, MyMacro (marco) and MyLib (target) depend on the same C target.

The compilation log is as follows:

$ swift --version
swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
Target: arm64-apple-macosx15.0

$ swift build
[1/1] Planning build
Building for debugging...
error: emit-module command failed with exit code 1 (use -v to see invocation)
<REDACTED>/CLib-tool.build/module.modulemap:1:8: error: redefinition of module 'CLib'
module CLib {
       ^
<REDACTED>/CLib.build/module.modulemap:1:8: note: previously defined here
module CLib {
       ^
<REDACTED>/CLib-tool.build/module.modulemap:1:8: error: redefinition of module 'CLib'
module CLib {
       ^
<REDACTED>/CLib.build/module.modulemap:1:8: note: previously defined here
module CLib {
       ^

Xcode 16.3 uses a different compilation strategy and only generates one modulemap, which can compile successfully.
Swift 6.0.3 can also compile successfully.

5 posts - 2 participants

Read full topic


Viewing latest article 23
Browse Latest Browse All 166

Trending Articles