Sure! In this example, I have built libgit2. I have a directory called Git, and 
inside that I have the following module map:

module Git [system] {
       header "<my path>/libgit2/include/git2.h"
       export *
}

When I run, I use:

swift -I <path-to-“Git”-directory> -L <path-to-built-libgit2> -lgit2 foo.swift

inside foo.swift I can:

import Git
// … use libGit2


Read more about how to write a more appropriate module.map file for your 
purposes at https://clang.llvm.org/docs/Modules.html 
<https://clang.llvm.org/docs/Modules.html>. For example, you might be able to 
define link flags inside the module.map, use umbrella directories, submodules, 
etc.



> On Mar 28, 2017, at 6:27 AM, Kelvin Ma <[email protected]> wrote:
> 
> Can you give an example?
> 
> On Mon, Mar 27, 2017 at 3:59 PM, Michael Ilseman <[email protected] 
> <mailto:[email protected]>> wrote:
> Sure. At a low level, you can create a module.map file and use -L/-l flags in 
> your invocation of Swift. If you want to do so at a higher level, then 
> perhaps SwiftPM can. CCing swift-build-dev for the SwiftPM part.
> 
> 
> > On Mar 26, 2017, at 3:20 PM, Kelvin Ma via swift-users 
> > <[email protected] <mailto:[email protected]>> wrote:
> >
> > Idk if this has been asked before, but is there a way to import C libraries 
> > into a Swift project without creating a local git repo? Preferably 
> > something similar to C where you can just `#include` headers and then 
> > specify the link flags (in Package.swift?)
> >
> > It’s getting very cumbersome to make a bunch of empty git repos just to use 
> > libglfw or libcairo.
> > _______________________________________________
> > swift-users mailing list
> > [email protected] <mailto:[email protected]>
> > https://lists.swift.org/mailman/listinfo/swift-users 
> > <https://lists.swift.org/mailman/listinfo/swift-users>
> 
> 

_______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to