[swift-users] Importing Empty C Structs
Jeff Kelley
slaunchaman at gmail.com
Thu Feb 11 23:41:22 CST 2016
I’m trying to use the Swift Package Manager to import libgit2 and am running into some issues. I have libgit2 installed via Homebrew and have configured the module map thusly:
> module CGit2 [system] {
> header "/usr/local/include/git2.h"
> link "git2"
> export *
> }
I can then use this with the SPM to initialize the Git system:
> import CGit2
>
> let result = git_libgit2_init()
>
> defer { git_libgit2_shutdown() }
>
> print("Result: \(result)")
This all works fine. When I start to try to use it—for instance, opening a repository:
> var repo: git_repository = nil
>
> let error = git_repository_open(&repo, "/Users/jeff/Projects/CGit2")
>
> guard let repo = repo else { print("No repo!"); exit(error) }
I get an error: “use of undeclared type ‘git_repository’”
Here’s how git_repository is declared in /usr/local/include/git2/types.h:
> typedef struct git_repository git_repository;
An empty struct. Interesting. A quick sample project in Xcode shows that this line will not generate anything in the Swift generated interface. So it appears to me that this type is invisible to Swift.
Question: Is there a way to use libraries like this in Swift? Should I file a bug that typedef’d structs like this are not imported into the generated interface? Thanks in advance for any pointers!
Jeff Kelley
SlaunchaMan at gmail.com | @SlaunchaMan <https://twitter.com/SlaunchaMan> | jeffkelley.org <http://jeffkelley.org/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160212/7f318090/attachment.html>
More information about the swift-users
mailing list