Compile C code and expose it to Swift under Linux
<p>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 <a href="https://github.com/apple/swift-corelibs-libdispatch" rel="nofollow noreferrer">libdispatch</a> are written in pure C and that you can access them in Swift just by importing them.</p>
<p>To set the example let's say that I have two files <code>Car.c</code> and <code>Car.h</code> that define structure named <code>Car</code>. Is there a way that I can compile them and use them in Swift by writing import statement?</p>
<pre><code>import Car
</code></pre>
<p>I've tried writing <code>module.modulemap</code> file inside directory where <code>.c</code>, <code>.h</code> and <code>Package.swift</code> files are located:</p>
<pre><code>module Car {
   header &quot;Car.h&quot;
   export *
}
</code></pre>
<p>and running <code>swift build</code>. This yield error:</p>
<pre><code>&lt;unknown&gt;:0: error: unexpected 'commands' value (expected map)
&lt;unknown&gt;:0: error: unable to load build file
</code></pre>
<p>I'm using Swift version 3.0-dev (March 24 2016)</p>
<p><strong>[Update 1]</strong></p>
<p>I've contacted Max(mxcl) - one of the creators of Swift Package Manager and he told me to get rid of the <code>modulemap</code> and put the <code>.c</code> and <code>.h</code> files directly in <code>Sources</code> 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 <code>.h</code> file.</p>