Is there a way to compile native C or C++ code and expose it to Swift on Linux? I can see that several Apple libraries like libdispatch are written in pure C and that you can access them in Swift just by importing them.
To set the example let's say that I have two files Car.c
and Car.h
that define structure named Car
. Is there a way that I can compile them and use them in Swift by writing import statement?
import Car
I've tried writing module.modulemap
file inside directory where .c
, .h
and Package.swift
files are located:
module Car {
header "Car.h"
export *
}
and running swift build
. This yield error:
<unknown>:0: error: unexpected 'commands' value (expected map)
<unknown>:0: error: unable to load build file
I'm using Swift version 3.0-dev (March 24 2016)
[Update 1]
I've contacted Max(mxcl) - one of the creators of Swift Package Manager and he told me to get rid of the modulemap
and put the .c
and .h
files directly in Sources
folder. After I did that package compiled but it's not available as module. Also I can't call any of the defined functions in the .h
file.