I work on an open source project in which we package a C++ library with SPM. I was testing a new version of the C++ lib the other day and ran into the following issue which I would like to understand better:
One of the .cpp files in the project uses
<algorithm> but does not import
<algorithm> explicitly. It does import
<vector>. When I build on macOS everything is fine, but when I build in a Swift Docker container, I get
error: no member named 'unique' in namespace 'std'.
Looking at the depfile, I see that the
<vector> being used on macOS is from LLVM's libcxx, which imports
<algorithm>. In the Docker container, however,
<vector> is from GNU's libstdc++ which apparently does not import
Our specific problem is easily fixed by adding
#import <algorithm>, but I'm now questioning whether I understand the behavior of the
cxxLanguageStandard option in the Swift package definition. Our Package.swift specifies
cxxLanguageStandard: .cxx11, and I previously thought that meant we'd get LLVM's libcxx on both macOS and Linux. The behavior described above leads me to believe that my understanding is flawed. Can anyone help explain what's going on?
FWIW, I tried changing the
.gnucxx11. The depfiles were nearly identical on macOS and were exactly identical on Linux.