You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?
Confirmed reproduction steps with SwiftPM CLI. The description text must include reproduction steps with either of command-line SwiftPM commands, swift build, swift test, swift package etc.
Description
I'm trying to define a target to act as a wrapper to a header-only C++ library (Eigen). I have followed the instructions in here: https://www.swift.org/documentation/cxx-interop/
However, when I run swift build I keep getting an error that complains about the library being unable to find <cmath> which should be available in the SDK include header paths as it's part of StdLib ?.
I tried adding unsafeFlags to include the lib parameter but no change (also I learned this is deprecated? I'm not a C++ developer so not sure here...).
I have attached a sample project with minimal code to reproduce the issue. BugRepro.zip
Expected behavior
swift build should work without any problems.
Actual behavior
swift build fails with error :
❯ swift build --verbose
warning: 'bugrepro': /Library/Developer/CommandLineTools/usr/bin/swift-frontend -frontend -c -primary-file /Users/alexander/dev/apple/BugRepro/Package.swift -target arm64-apple-macosx13.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I /Library/Developer/CommandLineTools/usr/lib/swift/pm/ManifestAPI -F /Library/Developer/CommandLineTools/Library/Developer/Frameworks -vfsoverlay /var/folders/m5/7nr7qwz951d9mn1l5qnsfncc0000gn/T/TemporaryDirectory.jsoL1M/vfs.yaml -swift-version 6 -package-description-version 6.0.0 -new-driver-path /Library/Developer/CommandLineTools/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Library/Developer/CommandLineTools/usr/lib/swift -module-name main -disable-clang-spi -target-sdk-version 15.2 -target-sdk-name macosx15.2 -external-plugin-path '/Library/Developer/Developer/usr/lib/swift/host/plugins#/Library/Developer/Developer/usr/bin/swift-plugin-server' -external-plugin-path '/Library/Developer/Developer/usr/local/lib/swift/host/plugins#/Library/Developer/Developer/usr/bin/swift-plugin-server' -plugin-path /Library/Developer/CommandLineTools/usr/lib/swift/host/plugins -plugin-path /Library/Developer/CommandLineTools/usr/local/lib/swift/host/plugins -o /var/folders/m5/7nr7qwz951d9mn1l5qnsfncc0000gn/T/TemporaryDirectory.DFui0Q/Package-1.o
/Library/Developer/CommandLineTools/usr/bin/clang /var/folders/m5/7nr7qwz951d9mn1l5qnsfncc0000gn/T/TemporaryDirectory.DFui0Q/Package-1.o -F /Library/Developer/CommandLineTools/Library/Developer/Frameworks --sysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk --target=arm64-apple-macosx13.0 /Library/Developer/CommandLineTools/usr/lib/swift/macosx/libswiftCompatibilityPacks.a -L /Library/Developer/CommandLineTools/usr/lib/swift/macosx -L /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/swift -L /Library/Developer/CommandLineTools/usr/lib/swift/pm/ManifestAPI -lPackageDescription -Xlinker -rpath -Xlinker /Library/Developer/CommandLineTools/usr/lib/swift/pm/ManifestAPI -o /var/folders/m5/7nr7qwz951d9mn1l5qnsfncc0000gn/T/TemporaryDirectory.anG2Ng/bugrepro-manifest
Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx13.0
Planning build
Building for debugging...
Write auxiliary file /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/swift-version--1AB21518FC5DEDBE.txt
/Library/Developer/CommandLineTools/usr/bin/swiftc -module-name BugRepro -emit-dependencies -emit-module -emit-module-path /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/Modules/BugRepro.swiftmodule -output-file-map /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/BugRepro.build/output-file-map.json -parse-as-library -incremental -c @/Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/BugRepro.build/sources -I /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/Modules -target arm64-apple-macosx10.13 -v -enable-batch-mode -index-store-path /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/index/store -Onone -enable-testing -j12 -DSWIFT_PACKAGE -DDEBUG -Xcc -fmodule-map-file=/Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/MyCLibrary.build/module.modulemap -Xcc -I -Xcc /Users/alexander/dev/apple/BugRepro/Sources/MyCLibrary/include -module-cache-path /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/ModuleCache -parseable-output -parse-as-library -emit-objc-header -emit-objc-header-path /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/BugRepro.build/BugRepro-Swift.h -color-diagnostics -swift-version 6 -F /Library/Developer/CommandLineTools/Library/Developer/Frameworks -sdk /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -g -Xcc -isysroot -Xcc /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -Xcc -fPIC -Xcc -g -package-name bugrepro
Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx10.13
/Library/Developer/CommandLineTools/usr/bin/swift-frontend -frontend -emit-module -experimental-skip-non-inlinable-function-bodies-without-types /Users/alexander/dev/apple/BugRepro/Sources/BugRepro/BugRepro.swift -target arm64-apple-macosx10.13 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/Modules -F /Library/Developer/CommandLineTools/Library/Developer/Frameworks -color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 6 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /Library/Developer/CommandLineTools/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Library/Developer/CommandLineTools/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/alexander/dev/apple/BugRepro -Xcc -fmodule-map-file=/Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/MyCLibrary.build/module.modulemap -Xcc -I -Xcc /Users/alexander/dev/apple/BugRepro/Sources/MyCLibrary/include -Xcc -isysroot -Xcc /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -Xcc -fPIC -Xcc -g -module-name BugRepro -package-name bugrepro -disable-clang-spi -target-sdk-version 15.2 -target-sdk-name macosx15.2 -external-plugin-path /Library/Developer/Developer/usr/lib/swift/host/plugins#/Library/Developer/Developer/usr/bin/swift-plugin-server -external-plugin-path /Library/Developer/Developer/usr/local/lib/swift/host/plugins#/Library/Developer/Developer/usr/bin/swift-plugin-server -plugin-path /Library/Developer/CommandLineTools/usr/lib/swift/host/plugins -plugin-path /Library/Developer/CommandLineTools/usr/local/lib/swift/host/plugins -emit-module-doc-path /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/Modules/BugRepro.swiftdoc -emit-module-source-info-path /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/Modules/BugRepro.swiftsourceinfo -emit-objc-header-path /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/BugRepro.build/BugRepro-Swift.h -emit-dependencies-path /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/BugRepro.build/BugRepro.emit-module.d -parse-as-library -o /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/Modules/BugRepro.swiftmodule -emit-abi-descriptor-path /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/Modules/BugRepro.abi.json
/Library/Developer/CommandLineTools/usr/bin/swift-frontend -frontend -c -primary-file /Users/alexander/dev/apple/BugRepro/Sources/BugRepro/BugRepro.swift -emit-dependencies-path /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/BugRepro.build/BugRepro.d -emit-reference-dependencies-path /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/BugRepro.build/BugRepro.swiftdeps -target arm64-apple-macosx10.13 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/Modules -F /Library/Developer/CommandLineTools/Library/Developer/Frameworks -color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 6 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /Library/Developer/CommandLineTools/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Library/Developer/CommandLineTools/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/alexander/dev/apple/BugRepro -Xcc -fmodule-map-file=/Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/MyCLibrary.build/module.modulemap -Xcc -I -Xcc /Users/alexander/dev/apple/BugRepro/Sources/MyCLibrary/include -Xcc -isysroot -Xcc /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -Xcc -fPIC -Xcc -g -module-name BugRepro -package-name bugrepro -disable-clang-spi -target-sdk-version 15.2 -target-sdk-name macosx15.2 -external-plugin-path /Library/Developer/Developer/usr/lib/swift/host/plugins#/Library/Developer/Developer/usr/bin/swift-plugin-server -external-plugin-path /Library/Developer/Developer/usr/local/lib/swift/host/plugins#/Library/Developer/Developer/usr/bin/swift-plugin-server -plugin-path /Library/Developer/CommandLineTools/usr/lib/swift/host/plugins -plugin-path /Library/Developer/CommandLineTools/usr/local/lib/swift/host/plugins -parse-as-library -o /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/BugRepro.build/BugRepro.swift.o -index-store-path /Users/alexander/dev/apple/BugRepro/.build/arm64-apple-macosx/debug/index/store -index-system-modules
error: emit-module command failed with exit code 1 (use -v to see invocation)
<module-includes>:1:9: note: in file included from <module-includes>:1:
1 | #import "/Users/alexander/dev/apple/BugRepro/Sources/MyCLibrary/include/MyCLibrary.h"
| `- note: in file included from <module-includes>:1:
2 |
/Users/alexander/dev/apple/BugRepro/Sources/MyCLibrary/include/MyCLibrary.h:4:10: note: in file included from /Users/alexander/dev/apple/BugRepro/Sources/MyCLibrary/include/MyCLibrary.h:4:
2 | #pragma once
3 |
4 | #include "../headers/custom_header.h"
| `- note: in file included from /Users/alexander/dev/apple/BugRepro/Sources/MyCLibrary/include/MyCLibrary.h:4:
/Users/alexander/dev/apple/BugRepro/Sources/MyCLibrary/include/../headers/custom_header.h:2:10: error: 'cmath' file not found
1 |
2 | #include <cmath>
| `- error: 'cmath' file not found
3 |
4 | int some_function(int a, int b) {
/Users/alexander/dev/apple/BugRepro/Sources/BugRepro/BugRepro.swift:4:8: error: could not build Objective-C module 'MyCLibrary'
2 | // https://docs.swift.org/swift-book
3 |
4 | import MyCLibrary
| `- error: could not build Objective-C module 'MyCLibrary'
5 |
6 | public func bugRepro() {
<module-includes>:1:9: note: in file included from <module-includes>:1:
1 | #import "/Users/alexander/dev/apple/BugRepro/Sources/MyCLibrary/include/MyCLibrary.h"
| `- note: in file included from <module-includes>:1:
2 |
/Users/alexander/dev/apple/BugRepro/Sources/MyCLibrary/include/MyCLibrary.h:4:10: note: in file included from /Users/alexander/dev/apple/BugRepro/Sources/MyCLibrary/include/MyCLibrary.h:4:
2 | #pragma once
3 |
4 | #include "../headers/custom_header.h"
| `- note: in file included from /Users/alexander/dev/apple/BugRepro/Sources/MyCLibrary/include/MyCLibrary.h:4:
/Users/alexander/dev/apple/BugRepro/Sources/MyCLibrary/include/../headers/custom_header.h:2:10: error: 'cmath' file not found
1 |
2 | #include <cmath>
| `- error: 'cmath' file not found
3 |
4 | int some_function(int a, int b) {
/Users/alexander/dev/apple/BugRepro/Sources/BugRepro/BugRepro.swift:4:8: error: could not build Objective-C module 'MyCLibrary'
2 | // https://docs.swift.org/swift-book
3 |
4 | import MyCLibrary
| `- error: could not build Objective-C module 'MyCLibrary'
5 |
6 | public func bugRepro() {
Steps to reproduce
Run swift build
Swift Package Manager version/commit hash
Swift Package Manager - Swift 6.0.3
Swift & OS version (output of swift --version ; uname -a)
swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0
Darwin MacBook-Pro.local 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:00:32 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6030 arm64
The text was updated successfully, but these errors were encountered:
.interoperabilityMode(.Cxx)] needs to go on the target that uses the C++ library.
--- Package.swift.orig 2025-01-13 09:52:44
+++ Package.swift 2025-01-13 09:59:29
@@ -15,10 +15,10 @@
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
- name: "MyCLibrary",
- swiftSettings: [.interoperabilityMode(.Cxx)]),
+ name: "MyCLibrary"),
.target(
name: "BugRepro",
- dependencies: ["MyCLibrary"])
+ dependencies: ["MyCLibrary"],
+ swiftSettings: [.interoperabilityMode(.Cxx)]),
]
)
Then it should build and you should be able to call the some_function().
Is it reproducible with SwiftPM command-line tools:
swift build
,swift test
,swift package
etc?swift build
,swift test
,swift package
etc.Description
I'm trying to define a target to act as a wrapper to a header-only C++ library (Eigen). I have followed the instructions in here: https://www.swift.org/documentation/cxx-interop/
However, when I run
swift build
I keep getting an error that complains about the library being unable to find<cmath>
which should be available in the SDK include header paths as it's part of StdLib ?.I tried adding
unsafeFlags
to include the lib parameter but no change (also I learned this is deprecated? I'm not a C++ developer so not sure here...).I have attached a sample project with minimal code to reproduce the issue.
BugRepro.zip
Expected behavior
swift build
should work without any problems.Actual behavior
swift build
fails with error :Steps to reproduce
Run
swift build
Swift Package Manager version/commit hash
Swift Package Manager - Swift 6.0.3
Swift & OS version (output of
swift --version ; uname -a
)swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0
Darwin MacBook-Pro.local 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:00:32 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6030 arm64
The text was updated successfully, but these errors were encountered: