# System library wrapper does not build on macOS 13 due to module redefinition errors

**URL:** <https://forums.swift.org/t/system-library-wrapper-does-not-build-on-macos-13-due-to-module-redefinition-errors/61881>\
**Category:** Package Manager\
**Tags:** system-library\
**Created:** [December 7, 2022, 12:57am UTC](https://forums.swift.org/t/system-library-wrapper-does-not-build-on-macos-13-due-to-module-redefinition-errors/61881 "2022-12-07T00:57:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fwcd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/fwcd/32/15804_2.png) [@fwcd](https://forums.swift.org/u/fwcd)\
**Post date:** [December 7, 2022, 12:57am UTC](https://forums.swift.org/t/system-library-wrapper-does-not-build-on-macos-13-due-to-module-redefinition-errors/61881/1 "2022-12-07T00:57:45Z")

</div>

Hi everyone, apologies if this is the wrong place to ask.

I'm currently debugging a problem where building a Swift package wrapping a system library errors on macOS 13 (Xcode 14.1, Swift 5.7, with Homebrew installed) with the following message:

```swift
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/ffi/module.modulemap:1:8: error: redefinition of module 'FFI'
module FFI [system] [extern_c] {
       ^
/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/include/ffi/module.modulemap:1:8: note: previously defined here
module FFI [system] [extern_c] {

```

The issue, from what I understand, is that the compiler tries to include both the Xcode header and the command-line tools header for `libffi`, causing a clash. A little bit of googling lead me to the following threads with similar issues, suggesting it might be an issue with Homebrew:

- [Redefinition of module issue](https://forums.swift.org/t/redefinition-of-module-issue/35221)
- [Building with a dependency that uses system libraries no longer works](https://forums.swift.org/t/building-with-a-dependency-that-uses-system-libraries-no-longer-works/35249)

Still, this feels like a strange issue. I've put together a simple example project that builds fine on Ubuntu, but errors on macOS (the GitHub Actions workflows confirm this):

[https://github.com/fwcd/swift-systemlib-demo](https://github.com/fwcd/swift-systemlib-demo)

The Xcode include seems to be coming from the `Foundation` import in `SystemlibDemo.swift` (removing it fixes the build) and the command-line tools include I am not sure about. Running `pkg-config --cflags libffi` yields

```swift
-I/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/include/ffi

```

which seems to be coming from `/opt/homebrew/Library/Homebrew/os/mac/pkgconfig/13/libffi.pc`:

```swift
homebrew_sdkroot=/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk
prefix=${homebrew_sdkroot}/usr
exec_prefix=/usr
libdir=${exec_prefix}/lib
toolexeclibdir=${libdir}
includedir=${prefix}/include/ffi

Name: libffi
Description: Library supporting Foreign Function Interfaces
Version: 3.4-rc1
Libs: -L${toolexeclibdir} -lffi
Cflags: -I${includedir}

```

Any ideas or suggestions on where my configuration went wrong or how to solve this module clash?
