SwiftPM compile multiple arch system library

Hello!

My package contains a wrapper for c library "notcurses", this library was installed with homebrew both with arm version and x86_64 version so I would have both versions of the lib.

I'm trying to build my package with
swift build -c release --arch x86_64 --arch arm64

But the linker is unable to find this library for the x86_64 platform.

What I tried is making a universal library with lipo -create and replacing the arm64 version lib with it, after that it did find the library but I got:

Undefined symbols for architecture x86_64:

What would be the best approach here?

Here is my project for the reference, thank you

After making a universal library with lipo -create and replacing the arm64 version of it, swift build -c release --arch x86_64 by itself is working. The issue arises only when both architectures are passed as arguments, as from what I understand, it starts building using xcodebuild instead.

The workaround I came up with is to build both binaries like this separately and then create a universal binary with lipo -create, but I think there should be a better way to do this.

The easiest thing to do to get a correct output here is to use xcodebuild to build your binary instead of swift build. At this time, the xcbuild backend for SwiftPM is not well supported, but using xcodebuild will work just fine. You can use xcodebuild -list to find the schemes that are automatically synthesised, and then build the appropriate one to get the binaries.

1 Like