Use a module map to import C headers

suggest change

A module map can simply import mymodule by configuring it to read C header files and make them appear as Swift functions.

Place a file named module.modulemap inside a directory named mymodule:

Inside the module map file:

// mymodule/module.modulemap
module mymodule {
    header "defs.h"
}

Then import the module:

// demo.swift
import mymodule
print("Empty color: \(Color())")

Use the -I directory flag to tell swiftc where to find the module:

swiftc -I . demo.swift   # "-I ." means "search for modules in the current directory"

For more information about the module map syntax, see the Clang documentation about module maps.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents