Calling a C header from Swift (example)
I could not find a simple example of Swift code calling a C header. So I made one.
Usage:
swift build
.build/debug/SomeSwift
or
swift build --configuration release
.build/release/SomeSwift
Sources/SomeC
).Sources/SomeSwift
).Package.swift
file : targets: [Target(name: "Bitset", dependencies: ["SwiftBitsetC"]),]
.Sources/SomeC
). You need at least one source file (somec.c
).import SomeC
and then you can call the C function as in SomeC.sayHello()
.That's it!
$ swift package generate-xcodeproj
generated: ./SwiftCallingCHeader.xcodeproj
$ open ./SwiftCallingCHeader.xcodeproj