Cannot use this package in a static library - `Missing required module '_AtomicsShims'` error.
In static library swift file, on attempt to import Atomics I'm getting Missing required module '_AtomicsShims' error.
This is structure of project in a nutshell:
- StaticLibA // has
Atomicsstatic SPM library as dependency (but NOT as "Link Binary with Libraries" phase)
- foo.swift // needs atomic stuff, so does
import Atomicswhich fails with the above error
- FrameworkB // links with StaticLibA
- has some swift files which depend on StaticLibA types
- ExecutableC // links with StaticLibA, FrameworkB & Atomics
- uses both the static lib and dynamic framework
The very same import Atomics works well and without errors when it's in a final executable swift files, so problem is specific for static library target only.
Note also that StaticLibA deliberately is NOT linked with Atomics - if I did so then step # 1 succeeds but then step # 3 fails with "ld: 465 duplicate symbols for architecture arm64". I believe it's b/c the very same symbols of Atomic lib comes to final executable from both StaticLibA and FrameworkB.
Could you please advice what could be wrong or missing? OR, is it just not supported yet configuration? Thanks!
Thanks for the report! Unfortunately the reproduction steps don't contain enough information to debug this problem -- could you please provide a sample project that exhibits this issue?
Yup, I'll prepare the sample soon. Thanks!
👋 Any news regarding this issue? I encountered the same problem when adding some tests to my iOS app.
To reproduce the issue:
- Create an iOS app with unit tests in Xcode
- Add the
swift-atomicspackage to your main target - Try to execute the tests on your M1 Pro Macbook Pro (Xcode 14.0.1 / macOS 12.6 in my case)
Hello,
I have the same issue as @gaetanzanella mentioned above.
The difference is that my project has the grpc-swift package dependency, which in turn uses swift-atomics.
Xcode 14.0.1 macOS 12.6.1 M1 Pro Macbook Pro
I'm also getting this error. Running a Multiplatform app and when I go to test it I'm getting this error "_atomicsshims" on every imported module in the test. The swift_atomics package is included on my target because of another package I'm using.
I'm also getting this error when trying to archive a Swift package (from the command line using xcodebuild archive) to convert my package into a framework.
The binary just looks to be absent after the first build step and it fails when trying to ld Swift Atomics. Sorry this is all pretty new to me - don't know what I don't know - happy to add any information that might be helpful here.
Hello,
I have the same issue too, but different Xcode version
Xcode 13.4.1 macOS 12.6.1 M1 Pro Macbook Pro
Hi🎉
I fix it㊗️
I imported it into the UITest bundle and was able to build it.
Added Atomic to Link Binary With Libraries.
Please see the attached photo.

Thanks for sharing the fix @keisukeYamagishi . Unfortuately for me, the error kept repeating for different packages because of AsyncHttpClient (which depends on a handful of such packages including swift-atomics and was used in one of my dependencies). I was able to run the tests only after removing it.
in case if anyone faces this issue recursively like me for multiple packages, then you can try the approach by duckduckgo/ios.
create a static framework in your project and add all Swift Packages to it. Then use that framework in all your targets. For tests, add the framework in your Build Phases like mentioned above by @keisukeYamagishi
Quick update: @gaetanzanella's sample project has been very helpful in reproducing this. (Thank you!)
Unfortunately it's a tooling issue, so the package won't be able to fix it on its own.
A proper fix is in the pipeline, but it will need time. @keisukeYamagishi's or @imthath-m's suggestions are currently the best workarounds that I am aware of.
Getting rid of the C module with something along the lines of https://github.com/apple/swift-atomics/pull/74 would likely also get rid of these issues. However, this will require some Swift compiler & stdlib work, so it will take time.
In my case, async-http-client was a dependency to a package I'm using, OpenAIKit, which is dependent upon swift-atomics (as @imthath-m mentioned) and adding that to my UI and unit test build phases as @gaetanzanella did allowed my tests to build.